Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
MonkeyManx
Forum Newbie
Posts: 4 Joined: Tue Jul 09, 2002 9:02 pm
Location: Phoenix, Arizona
Contact:
Post
by MonkeyManx » Tue Jul 09, 2002 9:02 pm
I am having trouble with this code. all it is supposed to do is act as a counter and a score keeper, for a rating script.
I always get this error: You have an error in your SQL syntax near 'WHERE ID=''' at line 1Error: 1
someone please help me or show me what i am doing wrong.
here is the code:
Code: Select all
<?
if ($SCORE > 10) {
echo "NO GOOD CHEATER!";
exit;
} else {
$PASS = "*****";
// DB connection information
$connection = mysql_connect("localhost", "cekkent", $PASS);
$db = mysql_select_db("cekkent", $connection);
// SQL Query
$result=mysql_query ("select * from rate where ID='$ID'") or die (mysql_error());
while($row=mysql_fetch_array($result)){
// Make that Mofo do something
$VOTES = $rowї"VOTES"];
$VOTES=$VOTES+1;
}
$result = mysql_query("UPDATE rate SET VOTES=$VOTES WHERE ID='$ID'");
if(!$result) {
die("<b>Error:</b> " . print mysql_error());
exit;
} elseif($result) {
print "Continue1";
}
$result=mysql_query ("select * from rate where ID='$ID'") or die (mysql_error());
while($row=mysql_fetch_array($result)){
// Make that Mofo do something
$SCORE1 = $rowї"SCORE"];
$SCORE=$SCORE1+$SCORE;
}
$result = mysql_query("UPDATE rate SET SCORE=$SCORE where ID='$ID'");
if(!$result) {
die("<b>Error:</b> " . print mysql_error());
exit;
} elseif($result) {
mysql_close ($connection);
print " Continue2";
}
}
?>
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Jul 10, 2002 2:15 am
It may help if you echo out your SQL statements so that you can check there's nothing wrong with the data going in, so:
Code: Select all
$sql = "SELECT * FROM rate WHERE ID='$ID'";
echo $sql;
$result=mysql_query ($sql) or die (mysql_error());
Where does the $ID variable come from?
Mac
PaTTeR
Forum Commoner
Posts: 56 Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:
Post
by PaTTeR » Wed Jul 10, 2002 8:05 am
$ID may be unset or epmty. If $ID comes from GET or POST request try with $_GET[ID] ($_POST[ID]), or $_COOKIE[ID] .
If your PHP version is earlier than 4.1.0 use $HTTP_*_VARS
Try something like this:
Code: Select all
$result=mysql_query ("select * from rate where ID='$_GETїID]'") or die (mysql_error());
mikeq
Forum Regular
Posts: 512 Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland
Post
by mikeq » Thu Jul 11, 2002 3:33 am
Strange one this because doing a query like this
select * from rate where ID='';
would just return an empty result set and not an error, so surely if the variable is empty the query would still run, just not return anything.
Are you sure ID is a valid column name in your table?
Mike