Jump to content

mysql query error - nothing seems wrong?


BluMess

Recommended Posts

Hi

 

I've gotten really confused about this. Here is a seemingly fine PHP script for sending a query to mysql:

 

$insert = mysql_query("INSERT INTO ".$new_table_name." VALUES('".mysql_real_escape_string($row['datetime'])."', '', '".mysql_real_escape_string($row['type'])."', '".mysql_real_escape_string($row['title'])."', '".mysql_real_escape_string($row['author'])."', '".mysql_real_escape_string($row['thumbnail'])."', '".mysql_real_escape_string($row['short_d'])."', '".mysql_real_escape_string($row['description'])."', ".$row['width'].", ".$row['height'].", '".mysql_real_escape_string($row['flash'])."', '".mysql_real_escape_string($row['status'])."', ".$row['hits'].", ".$row['favourites'].", ".$row['emails'].")");

 

Yet, it gives me this error (when inserting some dummy information):

 

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 'VALUES('2009-08-09 22:23:10', '', 'game', 'testgame', 'testuser', ' ', 'short_description_here', '' at line 1

 

What's going on here?!

here's the table structure:

 

CREATE TABLE IF NOT EXISTS `user_games` (

  `datetime` datetime NOT NULL,

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `type` varchar(15) NOT NULL DEFAULT 'game',

  `title` varchar(50) DEFAULT NULL,

  `author` varchar(20) DEFAULT NULL,

  `thumbnail` text,

  `short_d` varchar(60) DEFAULT NULL,

  `description` text,

  `width` int(4) DEFAULT NULL,

  `height` int(4) DEFAULT NULL,

  `flash` text,

  `status` varchar(15) NOT NULL DEFAULT 'pending',

  `hits` int(10) NOT NULL DEFAULT '0',

  `favourites` int(10) NOT NULL DEFAULT '0',

  `emails` int(10) NOT NULL DEFAULT '0',

  PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=146 ;

 

Thanks

Link to comment
Share on other sites

It would be to your advantage to build your query statement in a variable (then simply put the variable holding the query into the mysql_query() statement) so that you can echo it to see exactly what it is.

 

It's likely that the variable $new_table_name is empty.

You, sir, are a life saver :D

 

I put it into a string, echoed it and yes I'd forgotten to global $new_table_name (that query is in a function). Thanks a lot, I'll remember that trick!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.