Jump to content

Simple insert query error


herghost

Recommended Posts

Im sure this is simple, but I cannot see what my problem is!

 

I am hitting an error on my insert query

 

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 '1' at line 1

 

I know the output of $user_id is 1, so my error is on $mysavepath

 

$mysavepath = $folder.'/'.$worldname.'_'.date("dMjY");
	echo $mysavepath;
	$savepath = mysql_query("INSERT INTO saves (user_id,savepath) VALUES ('$user_id','$mysavepath')");
	echo '<br>'.$savepath;
	if(!mysql_query($savepath))
	{
		die('<br>Error: ' . mysql_error());
	}

 

however it all echos out ok?

 

188ea678f0dcdc8252aeb15e3c910408/world_15Jan152012
1
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 '1' at line 1

 

Can anyone see the problem?

 

Cheers

Dave

 

Link to comment
https://forums.phpfreaks.com/topic/255063-simple-insert-query-error/
Share on other sites

if(!mysql_query($savepath))

 

^^^ That logic is wrong. $savepath is the result from a mysql_query() statement (a bool true/1 in this case.) You cannot put a result from one query into another mysql_query() statement. The mysql_query() statement expects an SQL query string.

might try...

$mysavepath = $folder.'/'.$worldname.'_'.date("dMjY");
$query = "INSERT INTO saves (user_id,savepath) VALUES ('$user_id','$mysavepath')";
echo $query;
$result = mysql_query($query) or die('<br>Error: ' . mysql_error());

if(!mysql_query($savepath))

 

^^^ That logic is wrong. $savepath is the result from a mysql_query() statement (a bool true/1 in this case.) You cannot put a result from one query into another mysql_query() statement. The mysql_query() statement expects an SQL query string.

might try...

$mysavepath = $folder.'/'.$worldname.'_'.date("dMjY");
$query = "INSERT INTO saves (user_id,savepath) VALUES ('$user_id','$mysavepath')";
echo $query;
$result = mysql_query($query) or die('<br>Error: ' . mysql_error());

 

Thanks to both!

 

Sorted out my logic (as litebearers post) Still showing the error but saving as well, that will do for now, until I put all my components together.

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.