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
https://forums.phpfreaks.com/topic/154200-solved-getting-syntax-error/
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.

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

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.