Page 1 of 1

mysql insert statement

Posted: Wed Jun 22, 2005 11:09 pm
by drummer87
Hi all, I'm having trouble inserting data into a table in my mysql database. I've ben trying for over an hour to get it to work and have no idea why it isn't (I'm fairly new to PHP and SQL). Here's my code:

Code: Select all

<?php
include ( "dbconnect.php" );

if ( ($_FILES['fupload']['type'] == "image/gif") OR ($_FILES['fupload']['type'] == "image/png") OR ($_FILES['fupload']['type'] == "image/jpeg") ) {
$source = $_FILES['fupload']['tmp_name'];
$target = "photos/".$_FILES['fupload']['name'];
$targetthumb = "photos/thumb-".$_FILES['fupload']['name'];
move_uploaded_file( $source, $target );
print "<b>Upload successful</b><br>";
print "<a href=\"admin.php\">Return</a>";
} else {
print "Upload failed, please try again";
}
$title = $_POST[title];
$desc = $_POST[desc];
print $title."<br>";
print $desc."<br>";
print $target."<br>";
print $targetthumb."<br><br>";

$query = "INSERT INTO entries (ID, title, desc, filepath, thumbpath) VALUES('', '$title', '$desc', '$target', '$targetthumb')";

print $query."<br><br>";
mysql_query( $query ) or die ( mysql_error() );
mysql_close( $link );

?>
The problem is with the $query I think because the page parses fine.. I just get a MySQL error.
This is what I get from mysql_error():

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, filepath, thumbpath) VALUES('', 'third inr comic', 'hope t

Thank you all for having a look, it's really important I get this working (it's for a major project at school) and I am quite stumped at this point.

- Drummer87

Posted: Wed Jun 22, 2005 11:13 pm
by method_man
you have no value for the ID

Posted: Wed Jun 22, 2005 11:36 pm
by drummer87
Update.. thanks for your reply.. but i found that desc is actually a reserved keyword for MySQL so it was getting it's knikkers in a knot. Changed the table and all is fixed :D

Posted: Wed Jun 22, 2005 11:43 pm
by method_man
lol

Posted: Thu Jun 23, 2005 2:27 am
by timvw
or you could have written select `desc` from table...