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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Im having problems with my php code. Can ne1 tell me whats wrong?

    Im just starting out w/ php and im trying to do this code as a test, but I cant get it to work. It will always say something like this: Notice: Undefined variable: Comments in c:\program files\apache group\apache\htdocs\infor.php on line 6. Can anyone help me out with this? BTW, here is the code I used for the Form...
    Code:
    <form action="infor.php" method=POST>
    First Name: <input type=Text name="FirstName"><br>
    Last Name: <input type=Text name="LastName"><br>
    Email: <input type=Text name="Email"><br>
    Comments: <textarea name="Comments" rows=10 cols=50></textarea><br>
    <input type="submit">
    </form>
    and here is the code I used for the PHP script.
    Code:
    <?
    print("Your first name is $FirstName");
    print("Your last name is $LastName");
    print("Your Email is $Email");
    print("This is what you had to say: $Comments");
    ?>
    
    <form action="infor.php" method=POST>
    First Name: <input type=Text name="FirstName"><br>
    Last Name: <input type=Text name="LastName"><br>
    Email: <input type=Text name="Email"><br>
    Comments: <textarea name="Comments" rows=10 cols=50></textarea><br>
    <input type="submit">
    </form>
    Thanx in advance!

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    That because you are trying to print out variables that do not yet have values. This will happen when you try to load the page before the form fields are filled out. What you need to do is either put the php code in another page and submit the form to that page or put a flag variable in the code to check to see if the form has been submitted yet or not. Something like


    if(isset("submit")){
    print $Comments;
    }
    else{
    //do nothing
    }
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i do have two seperate pages. One page is info.html then it goes to infor.php.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    to learn syntax referencing, put this in your receiving page

    foreach($_POST as $var=$val)
    {
    echo '$_POST[\\'' .$var. '\\'] = ' .$val .'<br />';
    }


    you should access posted/getted/cookieed/sessioned/servered vars with the array definition followed by the variable name - eg $_SESSION['blat']
    Last edited by Ökii; 03-09-2003 at 07:44 PM.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

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