Click to See Complete Forum and Search --> : sql error


kproc
07-14-2007, 02:17 PM
Hi the below code is giving me this error and I cannot figure out why

SQL Error: INSERT INTO albumNames (user_id, name, location, desc, createdate) VALUES('63', 'Family Tip', 'mjljo', 'ln', now())
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, createdate) VALUES('63', 'Family Tip', 'mjljo', 'ln', now(

and ideas by


if(isset($_POST['create_album'])){

$location = $_POST['location'];
$name = $_POST['name'];
$desc = $_POST['desc'];
$user_id = $_SESSION['user_id'];

if(!$name){
$msg .= "You must enter an Album Name<br />";

header("location: $url?msg=$msg");

exit();
}

$query_create_album = ("INSERT INTO albumNames (user_id, name, location, desc, createdate)
VALUES('$user_id', '$name', '$location', '$desc', now())");

$sql = mysql_query($query_create_album)or die("SQL Error: $query_create_album<br>" . mysql_error());

$msg .= "New Photo Album has been created";

header("location: $url?msg=$msg");
exit;
}

?>

knowj
07-14-2007, 03:00 PM
you have the word desc in your query which is used for ORDER BY xxxx DESC.

I had this problem at work last week took me a hour to figure it out lol

NogDog
07-14-2007, 03:01 PM
Try using "back-tick" quotes around the column name `desc`, as it is a reserved word (used with ORDER BY, for instance).