diasansley Posted February 4, 2011 Share Posted February 4, 2011 how do i get a drop down value and store it in a another table as of now i am getting the value from one table showing it on drop down now once that is selected i need to insert it into another table. <html> <?php mysql_connect('localhost','root','') or die('Could not connect to mysql ' . mysql_error()); mysql_select_db("dbtest") or die(mysql_error()); if(isset($_POST['submit'])) { //$name=$_POST['val']; $id = $_POST['select']; $id=$row['name']; ?> <input type="text" name="name2" value="<?php echo $row['name'] ?>"><br /> <?php $query = "INSERT INTO sub (`sub`) values('" . $id . "')"; $result = mysql_query($query); if($query) { echo "query executed"; } } ?> <form id="name" action="<?php $_POST['SERVER_SELF'] ?>" method="POST" > <input type="text" name="name1"><br /> <select name="select" id="select"> <?php $query = "SELECT name,id FROM main"; $result = mysql_query($query); if($query) { while($row = mysql_fetch_array($result)) { $options .= '<option value="' . $row['name'] . '">' . $row['name'] . '</option>'; // $out .= "<option value=\" . $row['name'] . \" >' . $row['name'] . '</option>"; } } echo $options; ?> </select> <input type="submit" name="submit1"> </form> </html> Thanks the above seem to work. Quote Link to comment https://forums.phpfreaks.com/topic/226650-store-drop-down-value/ Share on other sites More sharing options...
denno020 Posted February 4, 2011 Share Posted February 4, 2011 When the form is submitted, the php script that handles the processing of that form will grab the value set in the drop down, and then use it in a query that will insert the value into the 'other' table. You obviously need to code that, but that's the general idea of what to do. Denno Quote Link to comment https://forums.phpfreaks.com/topic/226650-store-drop-down-value/#findComment-1169745 Share on other sites More sharing options...
diasansley Posted February 4, 2011 Author Share Posted February 4, 2011 if(isset($_POST['submit'])) is the problem it has to be "sumbit1" Thanks anyways Quote Link to comment https://forums.phpfreaks.com/topic/226650-store-drop-down-value/#findComment-1169749 Share on other sites More sharing options...
denno020 Posted February 4, 2011 Share Posted February 4, 2011 Oh so you have fixed the problem already? You didn't make that clear in the original post. Denno Quote Link to comment https://forums.phpfreaks.com/topic/226650-store-drop-down-value/#findComment-1169751 Share on other sites More sharing options...
diasansley Posted February 4, 2011 Author Share Posted February 4, 2011 i didnt get a solution when i posted it once i got a solution in wrote. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/226650-store-drop-down-value/#findComment-1169752 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.