Strange treatment of variables passed as hidden input values
Posted: Thu Oct 26, 2006 2:51 pm
I can't for the life of me figure out what is causing this problem. I have a form, and if the user is editing an existing record, I pass the record id as a "hidden" value, method is POST. For some reason, on my processing page it was failing to pick up $_POST id value (see my code below). So, in the course of testing, I ended up creating a 2nd hidden input value, just to see if I could pick it up on the processing side. Like this:
On the processing page, I have the following:
What's interesting is, as long as the "myTest" hidden INPUT comes after the "id" hidden INPUT on the submission page, everything works out fine. As soon as I delete the "id" hidden INPUT line from my code, it fails on the processing page (Notice: Undefined index: myTest in D:\mycomputeretc. on line 9). Same error if I reverse the order of the "hidden" INPUTs, if the "myTest" comes before the "id" line of code.
Any ideas? Is there some reason why repeating the echo of the "myID" variable allows the processing page to recognize it? Very strange.
Code: Select all
<?php if ($noEntry == "No"){ ?>
<INPUT type="hidden" NAME="id" VALUE="<?php echo "$myID" ?>">
<INPUT type="hidden" NAME="myTest" VALUE="<?php echo "$myID" ?>">
<?php } ?>Code: Select all
// set up insert variables
$sectionid=mysql_real_escape_string( $_POST['sectionid'] ) ;
$subsectionid=mysql_real_escape_string( $_POST['subsectionid'] ) ;
$headline=mysql_real_escape_string( $_POST['headline'] ) ;
$subheadline=mysql_real_escape_string( $_POST['subheadline'] ) ;
$bodycontent=mysql_real_escape_string( $_POST['bodycopy'] ) ;
$myTestVar=mysql_real_escape_string( $_POST['myTest'] ) ;
// Perform MySQL query to insert data
// IF UPDATING A RECORD
if (isset($_POST['myTest'])){
$recordid = $_POST['myTest'];
// set up the query
$dataUpdate = "UPDATE generalinfo SET headline='$headline',subheadline='$subheadline',bodycontent='$bodycontent' WHERE id ='$recordid'";
// run the query
mysql_query($dataUpdate) or die(mysql_error());
}Any ideas? Is there some reason why repeating the echo of the "myID" variable allows the processing page to recognize it? Very strange.