FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


MySQL problem :'(





bladesage
This is getting very frustrating to me. I keep trying to update the table "war", but I keep getting the same error over and over again!

The portion of the script that seems to cause the problem is
Code:
if(isset($_POST['name']))
   {
   $name = $_POST['name'];
   $war = $_POST['warriors'];
   $arc = $_POST['archers'];
   $sni = $_POST['snipers'];
   $dead = $_POST['dead'];
   $army = $_POST['army'];
   $query2 = "UPDATE war SET warriors=$war, archers=$arc, snipers=$sni, dead=$dead, army_count=$army "."WHERE name='$name' "."LIMIT 1";
   mysql_query($query2) or die("ERROR<br />".mysql_error());
   }


The error produced is
Code:
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 'WHERE name='bladesage' LIMIT 1' at line 1


HELP!!
Traveller
Since you already have all the assignments together in that line, anyway, why do you use concatenation to add the WHERE and LIMIT clauses?

Then again, when I construct a line like this, I concatenate everything (e.g. "UPDATE war SET warriors=".$war.", ...").

From the way you have this set up, I presume that the values you are updating are all numeric. Is that correct?

for further debugging, put the statement:
Code:
echo $query2."<BR>";
just before trying to execute the query, then post the result here. Then again, that may reveal the problem so readily that you may not need any further assistance. If so, please post it anyway, so that others may see the solution and learn from it.
bladesage
Thanks!

I got it working now, it turns out I had the input for the army_count called army_count, but I typed "$army = $_POST['army'];" instead of "$army = $_POST['army_count']".

So it was going like this
Code:
ERROR!

UPDATE war SET warriors=4, archers=9, snipers=7, dead=1231, army_count= WHERE name='bladesage' LIMIT 1


Thanks again!
Traveller
Great! Sometimes those little echo statements for debugging can come in handy. Of course, don't forget to remove them afterward.

Since this is now resolved, I'll go ahead and -close- it.
Related topics
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.