Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Location
    Kansas City
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    function/url help

    Hey guys, I am hoping someone can help me here. I have done search after search for the last several hours and cant find my solution. I am currently starting a website, and here is what I am trying to achieve. Instead of having a bunch of pages trying to use the same page with functions inside it.

    PHP Code:

    function main(){
    /* my code here */
    /* emphasis on the ?action=action */
    echo "<a href=index.php?action=signup>Signup</a>";
    }

    function 
    signup(){
    /* show signup page */

    Can someone please get me pointed in the right direction?

    PHP Code:
        switch($action){

            case 
    "main";
            
    main();
            break;

            case 
    "signup";
            
    signup();
            break;
        } 
    Last edited by Manix; 05-25-2011 at 11:31 AM.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    I think this is probably what you're trying to achieve:

    PHP Code:
    <?
    switch($_GET['action'])
       {
       case 
    "signup";
       
    signup();
       break;

       default;
       
    main();
       break;
       }
        
    function 
    main()
       {
       print <<<STOP
       <html>
       echo "<a href=index.php?action=signup>Signup</a>";
       </html>
    STOP;
       }

    function 
    signup()
       {
       print <<<STOP
       <html>
       <!--/* show signup page */-->
       </html>
    STOP;
       }  
    ?>
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New to the CF scene
    Join Date
    May 2011
    Location
    Kansas City
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok here is my current code

    PHP Code:

        
    if(!isset($_GET['action'])) { 
            
    $action "userMain";
        }

    function 
    userMain(){
        
        echo 
    "<a href=account.php?action=signup>Sign-Up";
        echo 
    "<input type=\"hidden\" name=\"action\" value=\"signup\">";
        
    $stop;
    }

    function 
    Signup(){
        if (
    $_SERVER['REQUEST_METHOD'] == "POST"){
            
    encryptPassword();
            
    insertUser();
        } else { 

    /* form code here */


        
    }
        
    $stop;
    }


    switch(
    $_GET['action']) {  /* <-- Line 105  */

            
    case "Signup":
            
    Signup();
            break;
            
            default;
               
    userMain();
               break;
            
            case 
    "userMain":
            
    userMain();
            break;

    Notice: Undefined index: action in C:\wamp\www\account.php on line 105

    the link shows up, and when clicked i still see the link but the error dissapeares.

  • #4
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    That error message is telling you there is no parameter named "action" in the query string attached to the url of your php script.

    Looks like you just need to do some Basic Debugging 101.

  • #5
    New to the CF scene
    Join Date
    May 2011
    Location
    Kansas City
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    is there somewhere i can read that tells what that is and how it works when the url is like that

    whatever.php?blah=this

  • #6
    New to the CF scene
    Join Date
    May 2011
    Location
    Kansas City
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i figured out my problem

    PHP Code:

    $action 
    = (isset($_GET['action'])) ? $_GET['action'] : "index";

    switch(
    $action) {


            default:
               
    index();
               break;
            
            case 
    "signup":
            
    signup();
            break;
            
            case 
    "forgotPassword":
            
    forgotPassword();
            break;
            
    }

    function 
    index(){
        
        echo 
    "This is index<br />";
        echo 
    "<a href=./test.php?action=signup>Sign-Up<br />";
        echo 
    "<a href=./test.php?action=forgotPassword>Forgot Password";
        
    }

    function 
    signup(){
        echo 
    "this is signup";    
    }

    function 
    forgotPassword(){
        
        echo 
    "this is the forgot password area";


  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    I think your problem was the use of the variable $stop.

    That isn't the same as I showed you. I showed you the use of a heredoc:

    <<< <label>

    <label>

    PHP Code:
    print <<<STOP //Print until stop
    <html>
    </
    html>
    STOP//STOP must be at the very left. No spaces, no tabs, No $ in front.
    //Just the word exactly as you see if after <<< followed by a semicolon. 
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Further, the default: action in your switch should be at the bottom as the LAST option.

    I've shown you how to use this correctly in my example.

    The default is supposed to be at the bottom so that it can handle anything the clauses above did not handle. By putting it at the top you're screwing with the way the switch was designed to work. Just like your twist on using $stop, you can't just take switch and decide to rewrite its mechanism for your own needs.

    I gave you good code to use. All you had to do was copy it and modify it to your needs.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by tangoforce View Post
    Further, the default: action in your switch should be at the bottom as the LAST option.

    I've shown you how to use this correctly in my example.

    The default is supposed to be at the bottom so that it can handle anything the clauses above did not handle. By putting it at the top you're screwing with the way the switch was designed to work.
    The default switch option doesn't need to be at the bottom, though you can argue that it's good for logical readability.

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Well yes because otherwise it takes responsibility for everything. If its at the top then there is no point having other cases after it.

    Lines of code do run from top to bottom..
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #11
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You didn't understand me. The default case placement does not matter. It performs the exact same way whether it's at the top, bottom, middle, etc.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •