marcs910 Posted June 19, 2006 Share Posted June 19, 2006 Ive searched and found a couple of ways this can be done but they arent matching up with what Ive used.Im currently reading "PHP and MySQL For Dynamic Web Sites" by Larry Ullman and this is where I am learning my code.What I'm trying to do is create a dropdown menu item to insert into a db. The codes I've tried from here isnt working with what I have. It creates the dropdown but never inserts the value. I'm including two textboxes that are working correctly, above and below in the form code.What will fix this or what am I doing wrong? Thanks [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] The SQL code im using:[code]if (isset($_POST['submitted'])) { require_once ('mysql_connect.php'); $query = "INSERT INTO homes (category, type, address, location, zip, year, bedroom, bathroom, garage, lotsize, stories, active, price, description, date_entered) VALUES ('$category', '$type', '$address', '$location', '$zip', '$year', '$bedroom', '$bathroom', '$garage', '$lotsize', '$stories', '$active', '$price', '$description', NOW())"; $result = @mysql_query ($query); [/code]The form code I'm using:[code]<p>Category:<input type="text" name="category" size "15" maxlength="15" value="<?php if (isset($_POST['category'])) echo$_POST['category']; ?>" /></p> <p>Active:<select size="1" name="active"> <option selected value="<?php if (isset($_POST['active'])) echo$_POST['active']; ?>">Y</option> <option value="<?php if (isset($_POST['active'])) echo$_POST['active']; ?>">N</option> </select></p> <p>Type:<input type="text" name="type" size "15" maxlength="15" value="<?php if (isset($_POST['type'])) echo$_POST['type']; ?>" /></p>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12386-insert-into-mysql-from-form-list-box/ Share on other sites More sharing options...
craygo Posted June 19, 2006 Share Posted June 19, 2006 Your form looks fine. The problem I see is with the variable on the insert. You need to set $catagory, $type, and $active.I believe you rcode would only work of global variable are turned on, which they are not by default and should not be.[code]if(isset($_POST['category'])){$category = $_POST['category''];}else{$category = '';}[/code]Each one would have to be setRay Quote Link to comment https://forums.phpfreaks.com/topic/12386-insert-into-mysql-from-form-list-box/#findComment-47446 Share on other sites More sharing options...
marcs910 Posted June 19, 2006 Author Share Posted June 19, 2006 [!--quoteo(post=385779:date=Jun 19 2006, 03:45 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Jun 19 2006, 03:45 PM) [snapback]385779[/snapback][/div][div class=\'quotemain\'][!--quotec--]Your form looks fine. The problem I see is with the variable on the insert. You need to set $catagory, $type, and $active.I believe you rcode would only work of global variable are turned on, which they are not by default and should not be.[code]if(isset($_POST['category'])){$category = $_POST['category''];}else{$category = '';}[/code]Each one would have to be setRay[/quote]Even if the rest of the fields are working fine? Quote Link to comment https://forums.phpfreaks.com/topic/12386-insert-into-mysql-from-form-list-box/#findComment-47454 Share on other sites More sharing options...
marcs910 Posted June 21, 2006 Author Share Posted June 21, 2006 *bimp* Quote Link to comment https://forums.phpfreaks.com/topic/12386-insert-into-mysql-from-form-list-box/#findComment-48003 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.