Jump to content

[SOLVED] Getting syntax error


almightyegg

Recommended Posts

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

 

my code is simply this:

$upfarm = mysql_query("UPDATE land SET type = 'Farm' WHERE userid = '{$mem['id']}' and type = 'none' LIMIT 0, $farm") or die(mysql_error());

 

in this case $farm = 1

 

Is there a problem with using the LIMIT in updates?

Link to comment
Share on other sites

Remove the 0, that is only needed if you want a range or a starting point (hence only used with select not update).

 

$upfarm = mysql_query("UPDATE land SET type = 'Farm' WHERE userid = '{$mem['id']}' and type = 'none' LIMIT $farm") or die(mysql_error());

 

And mafia created a syntax error, so do not use that one.

 

There is no reason to use LIMIT with UPDATE, since you are specifiing which row to be updated.

 

I would disagree. If you only want to update 1 record and know 1 record should be updated it is good to specify so. This prevents some mis-haps from happening.

Link to comment
Share on other sites

Problem is, I have 4 updates like this:

if($farm > 0){
$upfarm = mysql_query("UPDATE land SET type = 'Farm' WHERE userid = '{$mem['id']}' and type = 'none' LIMIT 0, $farm") or die(mysql_error());
}
if($water > 0){
$upwater = mysql_query("UPDATE land SET type = 'Water' WHERE userid = '{$mem['id']}' and type = 'none' LIMIT $farm, $water") or die(mysql_error());
}
if($train > 0){
$uptrain = mysql_query("UPDATE land SET type = 'Train' WHERE userid = '{$mem['id']}' and type = 'none' LIMIT $three, $train") or die(mysql_error());
}
if($casino > 0){
$upcasino = mysql_query("UPDATE land SET type = 'Casino' WHERE userid = '{$mem['id']}' and type = 'none' LIMIT $four, $casino") or die(mysql_error());
}

 

I need to start from certain rows so I don't rewrite over the rows I've onlky just updated

Link to comment
Share on other sites

I just wrote out a lengthy way to work around this and realised that you don't need to at all.

 

When you perform update number 2 the `type` field for update number 1 will already have been updated from 'none' to 'Farm' so it won't be possible to overwrite your new rows.

 

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.