icez Posted September 1, 2008 Share Posted September 1, 2008 Hey, I'm trying to add data from a drop down menu into my database... But What I did does not work. <?php if(isset($_POST['save'])) { $itemn = $_POST['itemn']; $realm = $_POST["realm"]; if(!get_magic_quotes_gpc()) { $itemn = addslashes($itemn); } $query = " INSERT INTO items (itemn, realm) ". " VALUES ('$itemn, '$realm')"; mysql_query($query) or die('Error ,query failed'); echo "'$itemn' on '$realm' added"; } ?> <form method="post"> <table width="700" border="0" cellpadding="2" cellspacing="1" align="center"> <tr> <td width="100">Item Name</td> <td><input name="itemn" type="text"></td> </tr> <tr> <td width="100">Realm</td> <td> <select name="realm"> <option value="------" >Select one</option> <option value="Us.East N-L Sofcore">Us.East N-L Sofcore</option> <option value="Us.East N-L Hardcore">Us.East N-L Hardcore</option> <option value="Us.East L Softcore">Us.East L Softcore</option> <option value="Us.East L Hardcore">Us.East L Hardcore</option> <option value="Us.West N-L Sofcore">Us.West N-L Sofcore</option> <option value="Us.West N-L Hardcore">Us.West N-L Hardcore</option> <option value="Us.West L Softcore">Us.West L Softcore</option> <option value="Us.West L Hardcore">Us.West L Hardcore</option> <option value="Europe N-L Sofcore">Europe N-L Sofcore</option> <option value="Europe N-L Hardcore">Europe N-L Hardcore</option> <option value="Europe L Softcore">Europe L Softcore</option> <option value="Europe L Hardcore">Europe L Hardcore</option> <option value="Asia N-L Sofcore">Asia N-L Sofcore</option> <option value="Asia N-L Hardcore">Asia N-L Hardcore</option> <option value="Asia L Softcore">Asia L Softcore</option> <option value="Asia L Hardcore">Asia L Hardcore</option> </select> </td> </tr> </table> <input name="save" type="submit" value="Save Item"> </form> Link to comment https://forums.phpfreaks.com/topic/122216-solved-drop-down-menu-mysql/ Share on other sites More sharing options...
valtido Posted September 1, 2008 Share Posted September 1, 2008 try and give the form an action to the php self by the way you said that it is not working? what happens when you click save ? what error do you get? add this bit. to your code } else{ echo 'Failed to add item'; } ?> <form method="post"> let us know wot error u get Link to comment https://forums.phpfreaks.com/topic/122216-solved-drop-down-menu-mysql/#findComment-630991 Share on other sites More sharing options...
ranjuvs Posted September 1, 2008 Share Posted September 1, 2008 A single quote is missing in your query after $itemn. $query = " INSERT INTO items (itemn, realm) ". " VALUES ('$itemn, '$realm')"; try using $query = " INSERT INTO items (itemn, realm) ". " VALUES ('$itemn', '$realm')"; Link to comment https://forums.phpfreaks.com/topic/122216-solved-drop-down-menu-mysql/#findComment-630993 Share on other sites More sharing options...
JasonLewis Posted September 1, 2008 Share Posted September 1, 2008 Just a note to add, for future reference. Instead of this: or die('Error ,query failed'); Actually display the error that mysql is returning by using mysql_error() or die("Error: ".mysql_error()); Much easier to debug then. Link to comment https://forums.phpfreaks.com/topic/122216-solved-drop-down-menu-mysql/#findComment-630996 Share on other sites More sharing options...
icez Posted September 1, 2008 Author Share Posted September 1, 2008 A single quote is missing in your query after $itemn. $query = " INSERT INTO items (itemn, realm) ". " VALUES ('$itemn, '$realm')"; try using $query = " INSERT INTO items (itemn, realm) ". " VALUES ('$itemn', '$realm')"; Lol, Thanks a lot man -.- Link to comment https://forums.phpfreaks.com/topic/122216-solved-drop-down-menu-mysql/#findComment-631003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.