Jump to content

Losing my Post Variable Values


Ceazon

Recommended Posts

Hello,

 

I have an problem. I have a page with form data. The idea is a user enters in the data clicks submit I post the data to the same page perform the calculation and display the result. This works perfectly the first time but when a user submits a second time the page returns blank results because the form values don't appear to be carried forward.

 

Simplified Code:

<html>
<head>


<title>*******</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#000066" text="#CCCCCC">
<?php

$volume1=addslashes($_POST['volume1']);
$price1=addslashes($_POST['price1']);
?>
<form name="Drink" action="" method="post">
  <table width="100%" border="1" align="center">
<tr>
	<td> Option 1 Name:</td>
	<td><input name="volume1" size="25" maxsize="25" type="text" value="<?php echo( $volume1)?>"/></td>
	<td> Option 2 Name:</td>
	<td><input name="price1" size="25" maxsize="25" type="text" value="<?php echo( $price1)?>"/></td>
</tr>
<tr>
      	<td colspan="2" align="right"><input type="submit" value="Submit"></td>
<td colspan="2"><input type="button" onclick="doReset()" value="Reset"/></td>
    </tr>
</table>
</form>
<?php
if($volume1!=""){
           echo($volume1+$price1);
}
?>
</body>
</html>

 

What's even worse is this works on my local host. It also works on my phone but over my IE and firefox browsers when I do it at my host it just stops working after the second time. When I view the page source I can see that the values for the fields are null.

 

Please Help Thanks!

Link to comment
https://forums.phpfreaks.com/topic/179547-losing-my-post-variable-values/
Share on other sites

Simplified Code:

Cannot really help you without seeing all the code responsible for the symptoms.

 

Best guess, you have same name post/get/session/cookie variables and register_globals are on and because register_globals cross-populates same name variables, the values are being overwritten when the part of the code you did not post processes the values and makes an assignment to for example some session variables.

Thanks for the help.

Even tho this is simplified code I get the exact same error. I upload this to my host run it once and the numbers add perfectly and the values are in the boxes but on my second submit I just get blanks and the form input values are set to "".

It also works on my phone but over my IE and firefox browsers when I do it at my host it just stops working after the second time

 

It works on your web host when you use your phone's browser?

 

2nd best guess, your IE/FF browsers are requesting the page twice and the second time the post variables are empty. Different browsers do this for different reasons, but since both IE and FF are affected, I would guess you are doing some URL rewriting that is causing the browsers to request the URL twice?

 

This still could be related to register_globals, what does a phpinfo() statement show for the register_globals settings on both your localhost and your web host?

On my local host: register_globals Off Off

on web server: register_globals Off Off

 

And the code I posted in its entirety when uploaded to my host has the same error. Maybe try uploading the code to your web host and see the results. I don't think any of the code I have there would cause it to request the page twice.

 

In general is this an acceptable practice to continually post the same data to the same page or is this just bad coding?

Archived

This topic is now archived and is closed to further replies.

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