Page 1 of 1

Can't locate problem with this query

Posted: Thu Nov 14, 2002 2:24 pm
by duhast
I am hoping someone can spot what I am doing wrong here. Everything is working right except for the UPDATE query which returns this error:

You have an error in your SQL syntax near ')' at line 1. I have been unable to figure out what is wrong. The code is as follows:

Code: Select all

mysql_select_db($database_dbi, $dbi);

$query_getstrike = "SELECT * FROM ".$user_prefix."_strike_count WHERE uname='$uname'";
$getstrike = mysql_query($query_getstrike, $dbi) or die(mysql_error());
$row_getstrike = mysql_fetch_assoc($getstrike);
$totalRows_getstrike = mysql_num_rows($getstrike);
$numstrikes=$row_getstrikeї'strikes'];
if($numstrikes < 3)&#123;
$numstrikes++;
$totalstrikes=$numstrikes;
echo "The number of strikes now is:$totalstrikes";// my variable checking code//


 mysql_query(" INSERT INTO ".$prefix ."_attendance ( tid, uname, mday, month, year, attend, comments )
VALUES ( '$tid', '$uname', '$mday', '$month', '$year','$attend', '$comments' )",$dbi) or die ("Couldn't insert info");
if (!isset($uname))&#123;
mysql_query(" INSERT INTO ".$prefix ."_strike_count ( uname, strikes) VALUES ('$uname','$strikes')", $dbi) or die (mysql_error());
&#125;
  else &#123;
 mysql_query(" UPDATE ".$prefix ."_strike_count SET strikes=$totalstrikes WHERE uname ='$uname')", $dbi) or die (mysql_error());
 &#125;
 &#125;
&#125;
I am new to this so I am sure it will be a silly mistake but I hope someone can spot where I went wrong in the query. Thanks!

Posted: Thu Nov 14, 2002 3:08 pm
by Rob the R
It looks to me like you have an extra ")" in your update statement (after the $uname).

Posted: Thu Nov 14, 2002 3:09 pm
by MeOnTheW3
(" UPDATE ".$prefix ."_strike_count SET strikes=$totalstrikes WHERE uname ='$uname')",$dbi)
Your error is telling you that you have a ")" in your statement that should not be there.

New code:

Code: Select all

&lt;?php
(" UPDATE ".$prefix ."_strike_count SET strikes=$totalstrikes WHERE uname ='$uname'", $dbi)
?&gt;

Posted: Thu Nov 14, 2002 6:57 pm
by duhast
AHHHH! Thank you so much! Now I feel foolish but I had been staring at that same line of code for too long and just couldn't see it straight. That was definitely the problem! Thanks again! :D

Posted: Fri Nov 15, 2002 6:24 am
by twigletmac
It always helps to store your SQL statements in their own variable so that you can echo them out to check for errors, it definitely makes debugging easier.

Mac