Jump to content

Recommended Posts

i have bumped into somthing else that causes a bug in my application.

i have a form which user a $_POST['cart']

 

for testing purposes when i print $_POST via print_r()

this is the output:

 

printing _POST

Array ( [cart] => Array ( [Men's Roller Blades] => 0 [Women's Roller Blades] => 0 [Helmet] => 0 [Knee Pads] => 0 [Knee and Elbow Pads] => 0 ) )

 

 

however once i click on the submit button which takes me to another page (my_cart.php)

 

when i print $_POST array i get the following:

 

printing _POST

Array ( [Men] => 0 [Women] => 0 [Helmet] => 0 [Knee_Pads] => 0 [Knee_and_Elbow_Pads] => 0 )

 

 

obviously it messes everything up. please help.

thank you! :)

Link to comment
https://forums.phpfreaks.com/topic/171040-strange-thing-about-_post-array-2/
Share on other sites

From your statements I am assuming you are posting the data twice. Are you populating the first post data into hidden fields? Are the parameters of those hidden fields enclosed in single quotes? If so, that secondary page would have input fields that look like this:

<input type='hidden' name='Men's Roller Blades' value='0' />

 

So, when it gets to the apostrophe in "Men's" it thinks that is the end of the name value for that field. You should do one or more of the following:

 

1) Use double quotes (but ensure you don't have any values with double quotes)

2) Escape any quotes in the parameter values

3) Don't "double post", instead save the first post data to session variables.

thank you for a very thorough response.

i should have posted my FORM code originally.

here it is:

<form action="my_cart.php" name="cart" method="post">
<?
//traversing outer array in this loop
//'name' is the 'key' and 'description' is the 'value' of this outer array
while (list($name, $description) = each($product))
{
	//calculating grand total of an item's 'price' and 'shipping' which are stored in the inner
	//array and are pointed by the keys 'price' and 'shipping' respectively
	$grand_total = calc_total($description["Price"], $description["Shipping"]);
	$shipping = $description["Shipping"] * $description["Price"];
?>
<tr>
	<td align="left"><? echo $name;?></td>
	<td align="left"><? echo number_format($description["Price"], 2);?></td>
	<td align="left"><? echo number_format($shipping, 2); ?></td>
	<td align="left"><input type="text" size="3" name="<?echo "$name";?>" value='<?$temp_number = 0; echo $_POST['cart']["$name"]=$temp_number;?>' /></td>
		<td align="right"><? echo number_format($grand_total, 2);?></td>
	</tr>
	<? 
}
echo "<br>printing _POST<br>";
print_r($_POST);
echo "<br>printing _SESSION<br>";
print_r($_SESSION);	
echo "<br>";
	// Print the footer, close the table, and the form:
	?><tr>
		<td colspan="4" align="right"><b>Total:</b></td>
		<td align="center">TEST</td>
	</tr>	
	<tr>
		<td colspan="6" align="center">TEST</td>
	</tr>
	</table><div align="center"><input type=submit value="SUBMIT"></div>
</form>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.