topshelfbleu Posted October 14, 2010 Share Posted October 14, 2010 I am retrieving a single row from a table and I want to use one of the fields in a post form which will be sent to process.php I have successfully use echo to place some results where I want them – but I want to use some of the row results as hidden fields. The code I am using to retrieve from the table is $result = mysql_query("SELECT qid,question,oc1 FROM tblquestions WHERE qid = '1'"); The oc1 field is the one I want to post by way of a hidden field so that it can be passed to the process.php. I have tried [/echo $row[2]; // oc1 $oc1 = $row[2];php] And then in the form: [code=php:0]<input type="hidden" name="oc1" id="oc1" value= <?php echo $oc1?> /> I think I just read that this can't actually be done- but I'm new to all this, so am not sure whether I've understood how I should be doing it instead. Any help REALLY gratefully received! Link to comment https://forums.phpfreaks.com/topic/215868-posting-variable-in-a-hidden-field/ Share on other sites More sharing options...
BlueSkyIS Posted October 14, 2010 Share Posted October 14, 2010 that should work, but make sure to quote or double-quote the value in the hidden field tag. Link to comment https://forums.phpfreaks.com/topic/215868-posting-variable-in-a-hidden-field/#findComment-1122159 Share on other sites More sharing options...
Pawn Posted October 14, 2010 Share Posted October 14, 2010 <?php $sql = "SELECT qid,question,oc1 FROM tblquestions WHERE qid = 1"; if(!$query = mysql_query($sql)) { echo mysql_error(); exit; } $row = mysql_fetch_assoc($query); ?> <input type="hidden" name="oc1" value="<?=$row['oc1']?>" /> Link to comment https://forums.phpfreaks.com/topic/215868-posting-variable-in-a-hidden-field/#findComment-1122160 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.