woolyg Posted May 4, 2007 Share Posted May 4, 2007 Hey all, I have a simple form, with a dropdown menu as one of the sources of data. Sources: Title (textfield) Group (dropdown menu) Body (textfield) In the processing PHP file, i connect to the db and specify <? $title = $_POST['title']; $group = $_POST['group']; $body = $_POST['body']; $query="INSERT INTO documentation (title, group, body) VALUES ('$title', '$group', '$body')"; mysql_query($query) or die ("That did not work"); ?> ..but the problem lies in trying to insert the group dropdown selection into the DB - when I remove it from the insert command, the data inserts OK. Have I used $_POST incorrectly? Cheers, Woolyg Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 4, 2007 Share Posted May 4, 2007 Change this line: mysql_query($query) or die ("That did not work"); To: mysql_query($query) or die (mysql_error()); So you can catch any errors if there is one. Double check your database tables spelling and any other spelling that might effect this. If you get no errors, post your form code. Quote Link to comment Share on other sites More sharing options...
woolyg Posted May 4, 2007 Author Share Posted May 4, 2007 Just get an error 1064 when I put in the mysql error handling - I know my syntax is incorrect.. Form code: <body> <form name="submitdoco" id="submitdoco" method="post" action="submitdoco.php"> <table width="100%" border="0"> <tr> <td>Username here </td> </tr> <tr> <td><select name="group" class="pg" id="group"> <option value="Rules" selected="selected">Rules</option> <option value="Club">Club</option> <option value="Other">Other</option> </select> Subject Group </td> </tr> <tr> <td><input name="title" type="text" class="pg" id="title" size="40" maxlength="255" /> Document Title </td> </tr> <tr> <td><input name="caption" type="text" class="pg" id="caption" size="40" maxlength="255" /> Caption (for quick & easy search reference) </td> </tr> <tr> <td><textarea name="full_body" cols="120" rows="10" class="pg" id="full_body">Main document body goes here. Try to be consice and to the point.</textarea></td> </tr> <tr> <td><input name="Submit" type="submit" class="pg" value="Submit for publishing" /></td> </tr> </table> </form> </body> And here's the processing PHP, after DB connection: <? $group = $_POST['group']; $title = $_POST['title']; $dts=time(); $timestamp=date('l M dS, Y, H:i:s'); $caption = $_POST['caption']; $full_body = $_POST['full_body']; $query = "INSERT INTO documentation (id, full_body, caption, timestamp, dts, title, group) VALUES ('null', '$full_body', '$caption', '$timestamp', '$dts', '$title', '$group')"; mysql_query($query) or die ("The document could not be added - ".mysql_errno()." - please contact the documentation administrator"); echo "Went in OK"; ?> For some reason it's not accepting the data from the dropdown part of the form. I've doublechecked all spelling.. Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 4, 2007 Share Posted May 4, 2007 before you process the query, echo the query to see exactly what its output is, so you can determine where the syntax is wrong.... Quote Link to comment Share on other sites More sharing options...
woolyg Posted May 5, 2007 Author Share Posted May 5, 2007 Ahhhh I found it guys - One of my columns on the table was called 'group' - mySQL thought I was using the command 'GROUP' - I've changed the column name and it goes in fine.. Wooly Quote Link to comment 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.