php/mysql error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bigdaddybass1258
Forum Newbie
Posts: 1
Joined: Thu Jun 17, 2010 9:00 am

php/mysql error

Post by bigdaddybass1258 »

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
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
I've beaten my head sideways trying to get the table to update. :banghead: 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.

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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php/mysql error

Post by AbraCadaver »

mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply