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 12 of 12
  1. #1
    New Coder
    Join Date
    Jan 2010
    Location
    In a dump
    Posts
    64
    Thanks
    9
    Thanked 2 Times in 2 Posts

    Assign variables from form

    I have a form which is a basic registration form. Whenever I submit the form it gives the error:

    Notice: Undefined index: email2 in /customers/encodedws.co.uk/encodedws.co.uk/httpd.www/iARC/signup.php on line 46

    Now, all i am doing is assigning variables values from the form. The names are exactly the same in the form as they are in the php which I thought was the issue. However when I echo the information it outputs the information from the variables but the entered info in the box email2 is output in the email1 variable. I dont understand what is going on.

    The PHP is just:

    PHP Code:
    $fName $_POST['name'];
        
    $sName $_POST['surname'];
        
    $eMail $_POST['email'];
        
    $eMail2 $_POST['email2']; << This gives error
        $pass 
    $_POST['pwd'];
        
    $pass2 $_POST['pwd2'];
        
        echo(
    '<p>Name is ' .$fName);
        echo(
    '<p>Surname is ' .$sName);
        echo(
    '<p>Email is ' .$eMail); << This outputs the erronious form element
        
    echo('<p>Email2 is ' .$eMail2);
        echo(
    '<p>Password is ' .$pass);
        echo(
    '<p>pass2 is ' .$pass2); 
    I have used the same code before but it does not work.
    Last edited by InterbredMonkey; 01-21-2010 at 04:24 PM.

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Can you post your form code (HTML)
    Edit: By the looks of it you're not sending email2 from the form, make sure that it's name and id are both the same value email2
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    I agree with Jay, I think it's in the form.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #4
    New Coder
    Join Date
    Jan 2010
    Location
    In a dump
    Posts
    64
    Thanks
    9
    Thanked 2 Times in 2 Posts
    The form is as follows:

    Code:
    <fieldset>
    	<legend>Sign up here</legend>
    		<form name = "frmsignup" action="signup.php" method = "post">
    			
                <label for="name">First Name:</label>
    				<input type = "text" name = "name" id = "name" tabindex = "4" size = "30" maxlength = "12" accesskey = "f" style="margin-left:48px; margin-top: 10px; border: 1px inset;"/>
    			
                <p/><label for="surname">Surname:</label>
    				<input type = "text" name = "surname" id = "surname" tabindex = "5" size = "30" maxlength = "12" accesskey = "s" style="margin-left:60px; border: 1px inset;"/>
    			
                <p/><label for="email">Email Address:</label>
    				<input type = "text" name = "email" id = "email" tabindex = "6" size = "30" maxlength = "60" accesskey = "m" style="margin-left:30px; border: 1px inset;" onblur= "checkEmail('email')" onchange="removeImg('email')"/>
    
                <p/><label for="email2">Confirm Email:</label>
    				<input type = "text" name = "email2" id = "email2" tabindex = "7" size = "30" maxlength = "60" accesskey = "a" style="margin-left:32px; border: 1px inset;" onblur="checkEmail('email2')" onchange="removeImg('email2')"/>
    
                <p/><label for="pwd" accesskey = "w">Password:</label>
    				<input type = "password" name = "pwd" id = "pwd" tabindex = "8" size = "30" maxlength = "20" style="margin-left:55px; border: 1px inset;" onblur="checkPass('pwd')" onchange="removeImg('pwd')"/>
    
                <label style="color:#6f6f6f; margin-left: 137px;">(Minimum of 6 characters in length)</label>
    			
                <p/><label for="pwd2" accesskey = "r">Confirm Password:</label>
    				<input type = "password" name = "pwd2" id = "pwd2" tabindex = "9" size = "30" maxlength = "20" style="margin-left:8px; border: 1px inset;" onblur = "checkPass('pwd2')" onchange="removeImg('pwd2')"/>
    
                <p/><input type = "submit" name = "signup" tabindex = "10" value = "Sign Up" style="display:block; margin-left:auto; margin-right:auto; font-family: Arial; font-size:12px;"/>
    		
            </form>
    	</fieldset>

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Odd, that looks fine. In your php file at the top put
    PHP Code:
    echo '<pre>'.print_r($_POSTtrue).'</pre>'
    and see what it produces. Paste the result here please
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #6
    New Coder
    Join Date
    Jan 2010
    Location
    In a dump
    Posts
    64
    Thanks
    9
    Thanked 2 Times in 2 Posts
    PHP Code:
    Array
    (
        [
    name] => simon
        
    [surname] => simon
        
    [email] => simon@home.com
        
    [email2] => simon@home.com
        
    [pwd] => simonrocks
        
    [pwd2] => SIMONROCKS
        
    [signup] => Sign Up

    I was going to ask why the second password was in capitals but I realised that I had pressed the caps. LoL.

  • #7
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Well your form is sending them fine

    Did that produce any errors?
    If it did, can you try just rewriting the line $eMail2 or use a different variable for it, just in case there's some bizarre character in there somewhere that's not been detected
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #8
    New Coder
    Join Date
    Jan 2010
    Location
    In a dump
    Posts
    64
    Thanks
    9
    Thanked 2 Times in 2 Posts
    yeah it seems to be working fine. That is so wierd!!

    Anyone know how to make it go back to the previous page and keep all the data in the form?

  • #9
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    I'm pretty sure it's browser dependant. Why exactly would you want it to go back and save the values? Surely that's going to give you problems with spammers etc. You should consider using a single page for php form processing, and check for form submission before processing the data. Take a look at this for a basic explanation of how to do this
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by InterbredMonkey View Post
    Notice: Undefined index: email2 in /customers/encodedws.co.uk/encodedws.co.uk/httpd.www/iARC/signup.php on line 46
    you use $email2 as index in a array but is no key with this name.

    best regards

  • #11
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Quote Originally Posted by oesxyl View Post
    you use $email2 as index in a array but is no key with this name.

    best regards
    Quote Originally Posted by InterbredMonkey View Post
    PHP Code:
    Array
    (
        [
    name] => simon
        
    [surname] => simon
        
    [email] => simon@home.com
        
    [email2] => simon@home.com
        
    [pwd] => simonrocks
        
    [pwd2] => SIMONROCKS
        
    [signup] => Sign Up

    clearly it had the index defined...
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #12
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by JAY6390 View Post
    clearly it had the index defined...
    this is op answer to your suggestion to print_r($_POST).

    best regards


  •  

    Posting Permissions

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