imarockstar Posted May 27, 2007 Share Posted May 27, 2007 hey guys im trying to insert some data from a drop down menu .. here is my code .. echo "Please select a Sub Category<br>"; echo " <select name='subcat' size='1'> <option value='Ex Girlfriend'>Ex Girlfriend</option> <option value='Asian'>Asian</option> <option value='Sex'>Sex</option> <option value='Party'>Party</option> <option value='Fan Sign'>Fan Sign</option> <option value='Oral'>Oral</option> <option value='Teen'>Teen</option> <option value='Tease'>Tease</option> <option value='Girl on Girl'>Girl on Girl</option> <option value='Cum Bath'>Cum Bath</option> <option value='Girl Next Door'>Girl Next Door</option> <option value='Cool Site'>Cool Site</option> <option value='Misc'>Misc</option> <option value='Myspace'>Myspace</option> <option value='Webcam girl'>Webcam Girl</option> </select> <br><br> "; when i submit it ..it puts the NAME "cat" in the database, im trying to get it to put the VALUE of the option in .. .what am I doing wrong. ps .. yes its a porno site ..haha Link to comment https://forums.phpfreaks.com/topic/53207-drop-down-menu-question/ Share on other sites More sharing options...
bubblegum.anarchy Posted May 27, 2007 Share Posted May 27, 2007 Post the insertion code. Link to comment https://forums.phpfreaks.com/topic/53207-drop-down-menu-question/#findComment-262886 Share on other sites More sharing options...
imarockstar Posted May 27, 2007 Author Share Posted May 27, 2007 if(isset($_POST['submit'])) { $url=$_POST['url']; $button=$_POST['button']; if(strlen($url)<1) { print "You did not enter a URL."; } else if(strlen($button)<1) { print "You did not enter a button."; } else { $insertbutton="INSERT into TABLENAME (url, image, cat, subcat) values('$url','$button','$cat','$subcat')"; mysql_query($insertbutton) or die(mysql_error()); print "Button added into system."; } } Link to comment https://forums.phpfreaks.com/topic/53207-drop-down-menu-question/#findComment-262893 Share on other sites More sharing options...
AndyB Posted May 27, 2007 Share Posted May 27, 2007 ... and where do the values of $cat and $subcat come from? Link to comment https://forums.phpfreaks.com/topic/53207-drop-down-menu-question/#findComment-262935 Share on other sites More sharing options...
imarockstar Posted May 28, 2007 Author Share Posted May 28, 2007 here is the whole code <?php if(isset($_POST['submit'])) { $url=$_POST['url']; $button=$_POST['button']; if(strlen($url)<1) { print "You did not enter a URL."; } else if(strlen($button)<1) { print "You did not enter a button."; } else { $insertbutton="INSERT into TABLENAME (url, image, cat, subcat) values('$url','$button','$cat','$subcat')"; mysql_query($insertbutton) or die(mysql_error()); print "Button added into system."; } } else { print "<form action='addlink.php' method='post'>"; print "URL(include http://):<br>"; print "<input type='text' name='url' size='20'><br>"; print "Image(button URL):<br>"; print "<input type='text' name='button' size='20'><br>"; echo "Pleae select a Category<br>"; echo " <select name='cat' size='1'> <option value='Affiliate'>Affiliate</option> <option value='Friend'>Friend</option> </select> <br><br> "; echo "Please select a Sub Category<br>"; echo " <select name='subcat' size='1'> <option value='Ex Girlfriend'>Ex Girlfriend</option> <option value='Asian'>Asian</option> <option value='Sex'>Sex</option> <option value='Party'>Party</option> <option value='Fan Sign'>Fan Sign</option> <option value='Oral'>Oral</option> <option value='Teen'>Teen</option> <option value='Tease'>Tease</option> <option value='Girl on Girl'>Girl on Girl</option> <option value='Cum Bath'>Cum Bath</option> <option value='Girl Next Door'>Girl Next Door</option> <option value='Cool Site'>Cool Site</option> <option value='Misc'>Misc</option> <option value='Myspace'>Myspace</option> <option value='Webcam girl'>Webcam Girl</option> </select> <br><br> "; print "<input type='submit' name='submit' value='submit'></form>"; } ?> to answer your above question ... i thought the values would come from the VALUE in the drop down ??? Link to comment https://forums.phpfreaks.com/topic/53207-drop-down-menu-question/#findComment-263065 Share on other sites More sharing options...
bubblegum.anarchy Posted May 28, 2007 Share Posted May 28, 2007 Did you write that code, imarockstar? Link to comment https://forums.phpfreaks.com/topic/53207-drop-down-menu-question/#findComment-263087 Share on other sites More sharing options...
Illusion Posted May 28, 2007 Share Posted May 28, 2007 First of all you need to give name to the form and then using the java script get the values of cat and subcat as given below $cat=document.formname.cat.options[document.formname.cat.selectedIndex].value $sub=document.formname.sub.options[document.formname.sub.selectedIndex].value Link to comment https://forums.phpfreaks.com/topic/53207-drop-down-menu-question/#findComment-263117 Share on other sites More sharing options...
bubblegum.anarchy Posted May 28, 2007 Share Posted May 28, 2007 First of all you need to give name to the form and then using the java script get the values of cat and subcat as given below $cat=document.formname.cat.options[document.formname.cat.selectedIndex].value $sub=document.formname.sub.options[document.formname.sub.selectedIndex].value A server side variable can not be assigned a client side javascript value. Link to comment https://forums.phpfreaks.com/topic/53207-drop-down-menu-question/#findComment-263213 Share on other sites More sharing options...
Illusion Posted May 28, 2007 Share Posted May 28, 2007 A server side variable can not be assigned a client side javascript value. then how to get the cat and subcat values using server side scripting assume that all the HTML tags are embedded in print statement. Link to comment https://forums.phpfreaks.com/topic/53207-drop-down-menu-question/#findComment-263219 Share on other sites More sharing options...
bubblegum.anarchy Posted May 28, 2007 Share Posted May 28, 2007 Predefined variables, depending on how the data is posted... either $_GET['subcat'] or $_POST['subcat'], or regardless of the method used $_REQUEST['subcat']; Have a read: http://au3.php.net/manual/en/language.variables.predefined.php Link to comment https://forums.phpfreaks.com/topic/53207-drop-down-menu-question/#findComment-263234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.