emailuser Posted November 29, 2007 Share Posted November 29, 2007 Hi , i am very new to php and am trying to change a php asset program to include another drop down menu , I have created the drop down and it shows the correct entries from Audit in sql , the process is that the user completes the php form for a new asset then clicks save to enter it to the database , the details below adds another drop down menu once they have selected the correct value i do not know how to capture this and write it back to the sql database ... help much appreciated ... // $sql = 'SELECT * FROM audit'; // $res = mysql_query($sql) or die(mysql_error()); // while ($rec = mysql_fetch_assoc($res)) $desc[] = $rec; // die('<pre>'.print_r($desc)); // echo '<SELECT name="dropdown">'; // foreach ($desc as $c) // { // if ($c['id'] == $_GET['id']) // echo "<OPTION value=\"{$c['id']}\" SELECTED>{$c['desc']}</OPTION>\n"; // else // echo "<OPTION value=\"{$c['id']}\">{$c['desc']}</OPTION>\n"; // } // echo '</SELECT>'; Link to comment https://forums.phpfreaks.com/topic/79396-newbie-question-updating-sql-from-drop-down-menu/ Share on other sites More sharing options...
PhaZZed Posted November 29, 2007 Share Posted November 29, 2007 One way would be to have a onclick=(); javascript event in the <select> tag, which then passes to php, which inserts the data into the database.. Link to comment https://forums.phpfreaks.com/topic/79396-newbie-question-updating-sql-from-drop-down-menu/#findComment-401945 Share on other sites More sharing options...
aschk Posted November 29, 2007 Share Posted November 29, 2007 You either need to do one of the following two: 1) An ajax call to update the database and then use javascript to add another populated dropdown (tricky) 2) Perform a "submit" and reload the same page after having parsed the information through PHP (preferred for your level) Link to comment https://forums.phpfreaks.com/topic/79396-newbie-question-updating-sql-from-drop-down-menu/#findComment-401949 Share on other sites More sharing options...
helraizer Posted November 29, 2007 Share Posted November 29, 2007 If I have caught the right meaning, it's pretty simple actually, in php. switch: <?php switch($dropdown) case "a" : return /*sql statement*/ ; case "b" : return /*sql statement*/ ; case "c" : return /*sql statement*/ ; ?> etc.. If I understood, that should work; if I got the wrong drift, please tell me. Sam Link to comment https://forums.phpfreaks.com/topic/79396-newbie-question-updating-sql-from-drop-down-menu/#findComment-402053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.