dannyone Posted March 16, 2009 Share Posted March 16, 2009 i have this code below which is cut down to show the main parts. i am selecting the room-id from a dynamic dropdown box from the table Rooms. then i want to be able to select when that room is free and store it in a table Rooms-Free using the room-id selected. i have all the arrays working fine but i can not use the selected value from the drop down. it stores in the database as room-id is 0. i assume i will need to make rooms.room-id = rooms-free.room-id but im not sure were. can some1 have a quick look and see how i can use the selected value. the value is stored as $nt as u will see from the code. <?php $nt = $_POST["Room_ID"]; if (!isset($_POST['submit'])) { ?> <form method="post" action="<?php echo $PHP_SELF;?>"> Select a Student:<br /> <?php //connects to db here $query=("SELECT Rooms.Room_ID,Rooms.RoomName,Rooms.Building FROM Rooms"); $result = mysql_query ($query); echo "<select name=Room_ID value=''>Room_ID</option>"; // printing the list box select command echo "<option>- Please Select Room -</option>\n"; while($nt=mysql_fetch_array($result)){ echo "<option post value=$nt[Room_ID]>$nt[Room_ID], $nt[RoomName] $nt[building]</option>"; "<br />"; } echo "</select>";// Closing of list box ?> <input type="submit" value="submit" name="submit"> <br /><br /> </form> <? }else{ echo "Your are view the availability or Room ID ".$nt.":<br /><br /><br />"; // this is echoing the room so $nt is working here } ?> <?php $WhatToInsert = array(); $WhatToInsert['Monday910'] = array('\'9-10\',\'mon\',\'Free\''); $WhatToInsert['Monday1011'] = array('\'10-11\',\'mon\',\'Free\''); // there are more arrays but these are working $sql1 = "replace Into Rooms_Free (Room_ID, timeslot, day, status) Values "; $sql2 = ""; foreach ($WhatToInsert as $key => $value) { if (isset($_REQUEST[$key])) { foreach ($WhatToInsert[$key] as $value2) { $sql2 .= (($sql2) ? ',(' : '(')."'$nt',$value2)"; //here is were i am stuck i need to use the selecte value from the dropdown to work with this $nt } } } $sql = (($sql2) ? $sql1.$sql2 : ""); if(!!$sql) { echo "<br/><FONT COLOR = RED>Your Availability has been set Thank You</FONT COLOR>"; } $conn = mysql_connect("localhost", "danny", "danny") or die ('Error connecting to mysql database!'); mysql_select_db("tutorial"); $query=mysql_query($sql); ?> thanks in advance for any help Link to comment https://forums.phpfreaks.com/topic/149707-really-need-help-with-selected-value/ Share on other sites More sharing options...
dannyone Posted March 16, 2009 Author Share Posted March 16, 2009 would i have to define $nt like it is done in this section below? in the foreach loop. // there are more arrays but these are working $sql1 = "replace Into Rooms_Free (Room_ID, timeslot, day, status) Values "; $sql2 = ""; foreach ($WhatToInsert as $key => $value) { if (isset($_REQUEST[$key])) { foreach ($WhatToInsert[$key] as $value2) { $sql2 .= (($sql2) ? ',(' : '(')."'$nt',$value2)"; //here is were i am stuck i need to use the selecte value from the dropdown to work with this $nt } } } $sql = (($sql2) ? $sql1.$sql2 : ""); if(!!$sql) { im really struggling to get to grips with this. please can some1 help thanks Link to comment https://forums.phpfreaks.com/topic/149707-really-need-help-with-selected-value/#findComment-786227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.