papaface Posted December 10, 2006 Share Posted December 10, 2006 Hello,I was wondering if someone can help me.Currently I have the following code in a script.[code]<?phprequire("includes/connect.php");/*fields: id title author description article*/if (isset($_POST["submit"])) {$title = $_POST["title"];$author = $_POST["author"];$description = $_POST["description"];$article = $_POST["article"];$category = $_POST["category"];$addtodb = "insert into article(title,author,description,article,category) values ('$title','$author','$description','$article','$category')";mysql_query($addtodb,$con); }else { $getcats = mysql_query("select name from cat",$con); echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post"> <label>Title: <input name="title" type="text"></label><br><br> <label>Author: <input name="author" type="text"></label><br><br> <label>Description: <textarea name="description" cols="60" rows="10"></textarea></label><br><br> <label>Article: <textarea name="article" cols="60" rows="30"></textarea></label><br><Br> <label>Select Category: <select>'; while (list($catname) = mysql_fetch_array($getcats)) { print '<option name="category" value="'.$catname.'">'.$catname.'</option>'; } echo '</select></label><br><br> <input name="submit" type="submit" value="Add Article!"> </form>'; }?>[/code]How can I get the value of the drop down menu passed to the SQL? Link to comment https://forums.phpfreaks.com/topic/30138-how-do-i-get-the-value-of-a-drop-down-menu/ Share on other sites More sharing options...
fert Posted December 10, 2006 Share Posted December 10, 2006 [code]<select name="name"><option value="value">value</option></select>[/code]Then $_POST['name'] or $_GET['name'] will contain the value of the select box. Link to comment https://forums.phpfreaks.com/topic/30138-how-do-i-get-the-value-of-a-drop-down-menu/#findComment-138555 Share on other sites More sharing options...
papaface Posted December 10, 2006 Author Share Posted December 10, 2006 Thanks. I didnt realise it would be that simple. Link to comment https://forums.phpfreaks.com/topic/30138-how-do-i-get-the-value-of-a-drop-down-menu/#findComment-138557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.