nloding Posted January 27, 2007 Share Posted January 27, 2007 I'm just trying to insert some form data into my table. I am successfully connection to the database. The table name is "pieces". It has the following fields in the following order:id / title / auth / pages / genre / format / desc / time / filenameid is auto_incremented, time is using the NOW() feature, so I'm putting data into the other fields. Here's my code:[code]//insert them variables into that there db$query = "INSERT INTO pieces (title, auth, pages, genre, format, desc, filename) VALUES ('$title', '$author', '$pages', '$genre', '$format', '$desc', '$file')";$result = $mysqli->query($query); //check to make sure the result is trueif($result) { echo "<p><span class=\"bold\"><u>Upload was successful!</u> ".$title." is now part of the library!</span></p>\n";}else { echo "<p>Something went wrong: ".$mysqli->error."</p>"; exit;}[/code]And here's the error I get:[quote]Something went wrong: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, filename) VALUES ('Test 4', 'Test 4', '4', 's_nonfiction', 'word', 'Test t' at line 1[/quote]I've double-checked all the spellings, variable names, and usage of apostrophes, and all seems to be in order. What am I missing?PS: Why isn't my code all colorful and exciting!? Link to comment https://forums.phpfreaks.com/topic/35997-error-inserting-data-into-table/ Share on other sites More sharing options...
pocobueno1388 Posted January 27, 2007 Share Posted January 27, 2007 [code]<?php//insert them variables into that there db$result = mysql_query( "INSERT INTO pieces (title, auth, pages, genre, format, desc, filename) VALUES ('$title', '$author', '$pages', '$genre', '$format', '$desc', '$file')"); //check to make sure the result is trueif($result) { echo "<p><span class=\"bold\"><u>Upload was successful!</u> ".$title." is now part of the library!</span></p>\n";}else { echo "<p>Something went wrong: ".$mysqli->error."</p>"; exit;}?>[/code] Link to comment https://forums.phpfreaks.com/topic/35997-error-inserting-data-into-table/#findComment-170752 Share on other sites More sharing options...
nloding Posted January 27, 2007 Author Share Posted January 27, 2007 Thanks poco, but that doesn't help. I'm using mysqli, and what you typed was the exact same thing I already had except not using mysqli.So what's wrong with my query?EDIT: Is it because I skip the id and time fields? Would adding "NULL" and "NOW()" to the INSERT query itself fix this? Let's try while I wait for a reply! Link to comment https://forums.phpfreaks.com/topic/35997-error-inserting-data-into-table/#findComment-170759 Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 DESC is an SQL keyword, you can't use it for a fieldname unless you escape it with `desc` Link to comment https://forums.phpfreaks.com/topic/35997-error-inserting-data-into-table/#findComment-170775 Share on other sites More sharing options...
nloding Posted January 27, 2007 Author Share Posted January 27, 2007 Excellent!jesirose, you've answered so many of questions ... THANK YOU THANK YOU! Link to comment https://forums.phpfreaks.com/topic/35997-error-inserting-data-into-table/#findComment-170777 Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 You should probably change the name to description so you don't keep having this problem in the future. Best of luck. Link to comment https://forums.phpfreaks.com/topic/35997-error-inserting-data-into-table/#findComment-170779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.