php/mysql error
Posted: Thu Jun 17, 2010 9:12 am
I'm not sure if I have the right forum or not but here it goes. I'm working on an e-voting system. On the last page there is a query that is used to update the DB to mark the user as voted by changing the count from 0 to 1. I'm getting an sql error
At this point I'm not sure if its cause I'm tackling the problem the wrong way or there is something wrong with the mysql query.
Any help in resolving this matter would be greatly appreciated. Thank you.
I've beaten my head sideways trying to get the table to update.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 'check="1" WHERE VoteID = "11134018"' at line 1
Code: Select all
<?php
// Connects to your Database
mysql_connect("localhost", "XXXXX", "hby596hGETnMphRS") or die(mysql_error());
mysql_select_db("Users") or die(mysql_error());
//Checks if there is a login cookie
if(isset($_COOKIE['Key_my_site']))
//if there isn't a cookie for the specified user it will return to the login page
{
$VoteID = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE VoteID = '$VoteID'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($VoteID != $info['VoteID'])
{
header("Location: login.php");
}
else
{
$check = 1;
$voted = "UPDATE users SET check=\"$check\" WHERE VoteID = \"$VoteID\"";
$perform = mysql_query($voted)or die(mysql_error());
echo $VoteID;
}
}
}
?>
<?php
$strCan = $_POST["cangroup"];
//echo $strCan."<br />";
mysql_connect("localhost", "XXXX", "hby596hGETnMphRS") or die(mysql_error());
mysql_select_db("Canidates") or die(mysql_error());
$sql = "SELECT * FROM canidates";
$showcan = mysql_query($sql)or die(mysql_error());
$name = mysql_result($showcan, 0, "name");
$name2 = mysql_result($showcan, 1, "name");
//echo $name ."<br />";
//echo $name2 ."<br />";
if($strCan==$name){
//echo "1 <br />";
$vote = mysql_result($showcan, 0, "voteCount");
//echo $vote ."<br />";
$vote++;
//echo $vote;
$insert = "UPDATE canidates SET voteCount=\"$vote\" WHERE name = \"$strCan\"";
$add_vote = mysql_query($insert);
}
elseif($strCan==$name2){
//echo "2 <br />";
$vote = mysql_result($showcan, 1, "voteCount");
//echo $vote ."<br />";
$vote++;
//echo $vote;
$insert = "UPDATE canidates SET voteCount=\"$vote\" WHERE name = \"$strCan\"";
$add_vote = mysql_query($insert);
}
?>
<html>
<head>
<title>Thank you</title>
</head>
<p>Thank you your vote has been casted.</p>
</html>Any help in resolving this matter would be greatly appreciated. Thank you.