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
https://forums.phpfreaks.com/topic/192988-mysql-query-error-nothing-seems-wrong/
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.

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!

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.