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

Link to comment
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());

 

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.

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.