Jump to content

Help needed with listbox.... insert to database {dynamically}


vine

Recommended Posts

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);

 

      ?>

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);

 

      ?>

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: :rtfm: :o::):confused: 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()); 

--------------------------------------------------------

 

 

 

:D :D :D  8) 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...  :rtfm: :rtfm: :rtfm: :rtfm: :rtfm: :P :P :P :P :P :P :P

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.