Page 1 of 1

Strange treatment of variables passed as hidden input values

Posted: Thu Oct 26, 2006 2:51 pm
by maxd
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:

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 } ?>
On the processing page, I have the following:

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());
}
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.

Posted: Thu Oct 26, 2006 2:54 pm
by volka
Please open the source view of your browser and copy&paste the complete code of the <form> element.

Posted: Thu Oct 26, 2006 4:18 pm
by maxd
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Here is the FORM source:

[syntax="html"]<FORM action="/admin/index.php?section=2&subsection=8&submit=1" method="POST" enctype="multipart/form-data">

<INPUT type="hidden" NAME="id" VALUE="76">
<INPUT type="hidden" NAME="myTest" VALUE="76">
<INPUT type="hidden" NAME="sectionid" VALUE="2">
<INPUT type="hidden" NAME="subsectionid" VALUE="8">

<H4>Headline:</h4>
<TEXTAREA NAME="headline" class="extrashallow" cols="" wrap="virtual">Irrigation Design & Auditing</TEXTAREA>

<H4>Subheadline:</h4>
<TEXTAREA NAME="subheadline" class="extrashallow" cols="" wrap="virtual"></TEXTAREA>

<H4>Body Copy:</h4>
<div id="fckeditorbox">
<div><input type="hidden" id="bodycopy" name="bodycopy" value="<h3>Irrigation Design</h3>
<p></p>" /><input type="hidden" id="bodycopy___Config" value="" /><iframe id="bodycopy___Frame" src="FCKeditor/editor/fckeditor.html?InstanceName=bodycopy&Toolbar=Default" width="400" height="500" frameborder="no" scrolling="no"></iframe></div></div>

<CENTER>
<INPUT TYPE="Submit" Value="Submit">
</center>

</form>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]