Jump to content

[SOLVED] Hidden field problem


chrispos

Recommended Posts

I am using a hidden field in a form. The idea is to send a number of hidden fields to pass to a form with each individual room having its own id. The site is a hotel booking site. I have tried

<?php echo$id;?>

But this does not work in this instance. I have tried a number of different ways but with no luck. The code is as follows:

$query = "SELECT * FROM `rooms`";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result)>0){ 
while ($row = mysql_fetch_row($result)) {
$rid=$row[0];
$hid=$row[1];
$number=$row[2];
$description=$row[3];
$sleeps=$row[4];
$booking = '<form id="form1" name="form1" method="post" action="/form2.php">
  <input name="id" type="hidden" id="id" value="$id" />
  <input name="hid" type="hidden" id="hid" value="$hid" />';
$booking1 = '<label>
  <input type="submit" name="Submit" value="Submit" />
  </label>
</form>';
  echo "$booking";
echo"$number\n\n";
echo"$description\n\n";
echo"$sleeps\n\n";
echo "$booking1<br><br>";
}
}

 

All the rooms show but as i want to send a number of different information ie $id $hid etc.

 

I would be happy of any help Thank you.

 

Link to comment
https://forums.phpfreaks.com/topic/151437-solved-hidden-field-problem/
Share on other sites

Variables inside single quotes are not expanded, change

<?php
$booking = '<form id="form1" name="form1" method="post" action="/form2.php">
  <input name="id" type="hidden" id="id" value="$id" />
  <input name="hid" type="hidden" id="hid" value="$hid" />';
?>

to

<?php
$booking = "<form id='form1' name='form1' method='post' action='/form2.php'>
  <input name='id' type='hidden' id='id' value='$id' />
  <input name='hid' type='hidden' id='hid' value='$hid' />";
?>

or

<?php
$booking = '<form id="form1" name="form1" method="post" action="/form2.php">
  <input name="id" type="hidden" id="id" value="' . $id . '" />
  <input name="hid" type="hidden" id="hid" value="' . $hid . '" />';
?>

 

Ken

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.