Help needed with listbox dynamically read and insert values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vine
Forum Newbie
Posts: 1
Joined: Sat Oct 10, 2009 2:52 am

Help needed with listbox dynamically read and insert values

Post by vine »

hi all ,,
i need help from you all i am struck up please help me the problem is i have two tables 1.hotel 2.rooms.. These two tables have common field called hotel_name as and when i enter the hotel name in the hotel table it should be added in the rooms table's corresponding form called as rooms.php in the listbox format displaying all the hotel names that are present in the hotel table i have done this.. Now i have to select one hotel from the listbox and insert the other values of rooms tables from rooms.php when i do it all fields are inserted except the hotel field ... please let me know how to insert the hotel field from listbox to my rooms table...

Thanks in advance for reference i will paste my code below.. ??? ???

<?php
if (count($errors) > 1)
echo "<p>There were some errors in your submitted form, please correct them and try again.</p>";
?>


<form method="post" action="<?=$_SERVER['PHP_SELF'] ?>" >






Room Type: <br \><input type="radio" name="roomtype" value="single">single <br \>
<input type="radio" name="roomtype" value="double">Double <br \>
<input type="radio" name="roomtype" value="twin">Twin <br \><br \>

Number of Rooms: <input type="text" name="noofrooms" size="30" value="<?= htmlentities($values['noofrooms']) ?>" class="error"><?= $errors['noofrooms'] ?><br /><br />
Cost: <input type="text" name="cost" size="30" value="<?= htmlentities($values['cost']) ?>" class="error"><?= $errors['cost'] ?><br /><br />
Admin Only: <input type="checkbox" name="adminony" > Yes <br \> <br \>
Date: <input type="text" name="date" size="30" value="<?= htmlentities($values['date']) ?>" class="error"><?= $errors['date'] ?><br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="submit" type="submit" value="save"/>&nbsp;&nbsp;&nbsp;
<input name="reset" type="submit" value="cancel" />
</form>
</body>
</html>
<?php

}
mysql_connect("localhost","root","root") or die('Error:' .mysql_error());
mysql_select_db("ems");
$project_sql="select hotel from hotels";
$rs=mysql_query($project_sql);
echo"Hotel:<select name='hotel' id='hot'>";
while($project_rows=mysql_fetch_array($rs))
{
echo"<option value=\"".$projects_rows['hotel']."\">".$project_rows['hotel']."\n";

$ans=$_GET['hotel'];
echo $ans;


}

echo"</select>";





// function ProcessForm($values)

//{











if ($_SERVER['REQUEST_METHOD'] == 'POST')

{

$formValues = $_POST;

$formErrors = array();



if (!VerifyForm($formValues, $formErrors))

DisplayForm($formValues, $formErrors);

else


<html>
<body>
<?php
$ans=$_GET['hotel'];
// $projects_rows=$_POST['hotel'];
$sa=$_POST['roomtype'];
$st=$_POST['noofrooms'];
$da=$_POST['cost'];
$dt=$_POST['adminonly'];
$ta=$_POST['date'];
//$tt=$_POST['twins_taken'];


mysql_connect("localhost","root","root") or die('Error:' .mysql_error());
mysql_select_db("ems");
?>

<?php
$query="insert into roomsa(hotel,roomtype,noofrooms,cost,adminonly,date)values ('".$ans."','".$sa."','".$st."','".$da."','".$dt."','".$ta."')";




mysql_query($query) or die ('Error:' .mysql_error());


?>
<form action="hotel.php" method="post">
<input type="submit" value="view records">
</form>
</body>
</html> <?php

// ProcessForm($formValues);

}

else

DisplayForm(null, null);

?>
Post Reply