...

View Full Version : Resolved Assign variables from form



InterbredMonkey
01-21-2010, 02:10 PM
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:


$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.

JAY6390
01-21-2010, 02:24 PM
Can you post your form code (HTML)
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

masterofollies
01-21-2010, 02:38 PM
I agree with Jay, I think it's in the form.

InterbredMonkey
01-21-2010, 02:46 PM
The form is as follows:


<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>

JAY6390
01-21-2010, 02:48 PM
Odd, that looks fine. In your php file at the top put

echo '<pre>'.print_r($_POST, true).'</pre>';
and see what it produces. Paste the result here please

InterbredMonkey
01-21-2010, 02:54 PM
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.

JAY6390
01-21-2010, 02:57 PM
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

InterbredMonkey
01-21-2010, 03:13 PM
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?

JAY6390
01-21-2010, 03:38 PM
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 (http://www.jaygilford.com/php/how-to-process-a-form-with-php-using-one-page/) for a basic explanation of how to do this

oesxyl
01-22-2010, 02:21 PM
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

JAY6390
01-22-2010, 03:20 PM
you use $email2 as index in a array but is no key with this name.

best regards



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...

oesxyl
01-22-2010, 05:35 PM
clearly it had the index defined...
this is op answer to your suggestion to print_r($_POST).

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum