PHP _POST vars returning with wrong key

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dave1909
Forum Newbie
Posts: 22
Joined: Sat Jul 25, 2009 8:56 pm

PHP _POST vars returning with wrong key

Post by dave1909 »

When i post a form and retrieve the $_POST data, one of the keys is wrong

Code: Select all

<form name="input" action="" method="post" >
		<label for="email">Email</label><input type='email' name='email' id='email' />
			<span id='email_error'>
				<? if(isset($signup_errors)){if(array_key_exists('email',$signup_errors)){echo $signup_errors[email];}}?>
			</span>
			<br />
		<label for="password">Password</label><input type='password' name='password' id='password'  />
			<span id='password_error'>
				<? if(isset($signup_errors)){if(array_key_exists('password',$signup_errors)){echo $signup_errors[password];}}?>
			</span>
			<br />
		<label for="passwordc">Confirm</label><input type='password' name='passwordc' id='passwordc' />
			<span id='passwordc_error'>
				<? if(isset($signup_errors)){if(array_key_exists('passwordc',$signup_errors)){echo $signup_errors[passwordc];}}?>
			</span>
			<br />
		<input type='submit' id='submitform' name='s5' value='submit4' />
	</form>	
a var_dump of $_POST returns this

Code: Select all

array(3) { ["email"]=> string(13) "test@test.com" ["password"]=> string(9) "testingpw" ["pwc"]=> string(9) "testingpw" }
As you will note, there is no 'pwc' field in my form. Why is it getting 'pwc' instead of 'passwordc'

This has really baffled me, it's never happened before.
User avatar
azycraze
Forum Commoner
Posts: 56
Joined: Mon Oct 24, 2011 12:08 pm
Location: India

Re: PHP _POST vars returning with wrong key

Post by azycraze »

change the 'passwordc' and give some other name and see what var_dump of $_POST returns
dave1909
Forum Newbie
Posts: 22
Joined: Sat Jul 25, 2009 8:56 pm

Re: PHP _POST vars returning with wrong key

Post by dave1909 »

changed form to . . .

Code: Select all

	<form name="input" action="" method="post" >
		<label for="email">Email</label><input type='email' name='email' id='email' />
			<span id='email_error'>
				<? if(isset($signup_errors)){if(array_key_exists('email',$signup_errors)){echo $signup_errors[email];}}?>
			</span>
			<br />
		<label for="password">Password</label><input type='password' name='password' id='password'  />
			<span id='password_error'>
				<? if(isset($signup_errors)){if(array_key_exists('password',$signup_errors)){echo $signup_errors[password];}}?>
			</span>
			<br />
		<label for="newvarname">Confirm</label><input type='password' name='newvarname' id='newvarname' />
			<span id='passwordc_error'>
				<? if(isset($signup_errors)){if(array_key_exists('passwordc',$signup_errors)){echo $signup_errors[passwordc];}}?>
			</span>
			<br />
		<input type='submit' id='submitform' name='s5' value='submit4' />
	</form>	

Code: Select all

array(3) { ["email"]=> string(13) "test@test.com" ["password"]=> string(9) "testingpw" ["pwc"]=> string(9) "undefined" }
Using 'Inspect element' on chrome verified that the input element has the name 'newvarname' but i still get the 'pwc' returning
dave1909
Forum Newbie
Posts: 22
Joined: Sat Jul 25, 2009 8:56 pm

Re: PHP _POST vars returning with wrong key

Post by dave1909 »

Oh my, my own stupidity amazes me.

I was using jquery to submit the form and didnt change the data i was sending with the AJAX call
Post Reply