Jump to content

[SOLVED] sql error


proctk

Recommended Posts

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;
}

?> 

Link to comment
https://forums.phpfreaks.com/topic/59984-solved-sql-error/
Share on other sites

I'm not sure what you are refering to

 

here is the table structure

 

albumNames  CREATE TABLE `albumNames` (                       

              `id` int(10) NOT NULL auto_increment,           

              `user_id` int(10) NOT NULL,                     

              `name` varchar(50) NOT NULL,                     

              `location` varchar(50) NOT NULL,                 

              `desc` text NOT NULL,                           

              `createdate` date NOT NULL default '0000-00-00', 

              PRIMARY KEY  (`id`)                             

            ) ENGINE=MyISAM DEFAULT CHARSET=latin1             

 

Link to comment
https://forums.phpfreaks.com/topic/59984-solved-sql-error/#findComment-298344
Share on other sites

IN is a MySQL reserved word and should not be used for fieldnames or tablenames.  Use something else as the field name.

 

http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html

 

In was a value he was trying to insert into the data, not a field name.

Link to comment
https://forums.phpfreaks.com/topic/59984-solved-sql-error/#findComment-298346
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.