vine Posted October 9, 2009 Share Posted October 9, 2009 hi all ,, i need help from you all i am struck up plz 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 /> <input name="submit" type="submit" value="save"/> <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); ?> Link to comment https://forums.phpfreaks.com/topic/177090-help-needed-with-listbox-insert-to-database-dynamically/ Share on other sites More sharing options...
vine Posted October 10, 2009 Author Share Posted October 10, 2009 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 /> <input name="submit" type="submit" value="save"/> <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); ?> Link to comment https://forums.phpfreaks.com/topic/177090-help-needed-with-listbox-insert-to-database-dynamically/#findComment-934144 Share on other sites More sharing options...
vine Posted October 10, 2009 Author Share Posted October 10, 2009 c'mon freaks whats the problem please help me :'( :'( :'( :'( :'( :'( Link to comment https://forums.phpfreaks.com/topic/177090-help-needed-with-listbox-insert-to-database-dynamically/#findComment-934178 Share on other sites More sharing options...
vine Posted October 12, 2009 Author Share Posted October 12, 2009 hey i have solved my problem half atleast this time home hoping some replies.. now i can insert the selected value from listbox to :rtfm: mysql table but the problem now is whatver value i select from the list box it is taking the first inserted value help me :-\ :-\ :-\ code..:- $query = "SELECT hotel FROM hotels"; $result = mysql_query($query); print "<SELECT name='lhotel'>"; while ($line = mysql_fetch_array($result)) { foreach ($line as $value) { print "<OPTION value='$value'"; // code for dynamically populate list box } print ">$value</OPTION>"; } mysql_close($link); print "</SELECT>"; <?php // $ans=$_GET['hotel']; // $projects_rows=$_POST['hotel']; $hotel=$_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('".$value."','".$sa."','".$st."','".$da."','".$dt."','".$ta."')"; echo $query; // echo $lhotel; //echo $hotel; //$ra= $_get['$lhotel']; // echo $ra; //$ra1= $_get['hotel']; // echo $ra1; mysql_query($query) or die ('Error:' .mysql_error()); -------------------------------------------------------- Link to comment https://forums.phpfreaks.com/topic/177090-help-needed-with-listbox-insert-to-database-dynamically/#findComment-935365 Share on other sites More sharing options...
vine Posted October 13, 2009 Author Share Posted October 13, 2009 :D as no one in the forum replied for my posts i thought of helping myself and finally i have got solution for my problem thanks mates...... the problem was with the code and the other problem was i needed to use it in form tag.... hahah cheers... :P :P :P Link to comment https://forums.phpfreaks.com/topic/177090-help-needed-with-listbox-insert-to-database-dynamically/#findComment-936027 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.