Jump to content

Posting Variable in a hidden field.


topshelfbleu

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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.