mysql insert statement

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
drummer87
Forum Newbie
Posts: 2
Joined: Wed Jun 22, 2005 10:58 pm
Location: Australia

mysql insert statement

Post 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
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

Post by method_man »

you have no value for the ID
drummer87
Forum Newbie
Posts: 2
Joined: Wed Jun 22, 2005 10:58 pm
Location: Australia

Post 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
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

Post by method_man »

lol
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

or you could have written select `desc` from table...
Post Reply