Twist3d Posted December 22, 2009 Share Posted December 22, 2009 Hell again. Well what im trying to do as usual as build this Toplist. What this code is supposed to do, Is Log the IP address in a Field in a Mysql Database. Then Updates votes the the ID = the ID from the GET thing on the previous page. But it gives me this 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 ''23' at line 1 Here is my code: <?php $dbhost = "mysql"; //Database Host $dbuser = "16584_toplist"; //Database User $dbpass = "PASSWORD"; //Database Password $dbname = "16584_toplist"; //Database Name //connect $db = mysql_pconnect($dbhost,$dbuser,$dbpass); mysql_select_db("$dbname",$db); $id = $_GET['id']; $name = $_GET['name']; $ip=$_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO iplog (IP) VALUES ('$ip')") or die(mysql_error()); mysql_query("UPDATE data SET votes=+1 WHERE id='$id") or die(mysql_error()); echo "<center>You have just voted for $name</center>"; echo "<center>Click <a href=viewtoplist.php>To view the toplist</center>"; ?> I have left the connection to the mysql up, because Line 1 is that, but i have used this exact code on ALL of my other files that need connecting to the Mysql database, and it works fine. Any help? ----------------- P.S I just found out that this code actually Logs the IP address, but it doesn't set the votes to +1. If thats the problem, i need help on that. Link to comment https://forums.phpfreaks.com/topic/186016-mysql-error/ Share on other sites More sharing options...
teynon Posted December 22, 2009 Share Posted December 22, 2009 mysql_query("UPDATE data SET votes=+1 WHERE id='$id") or die(mysql_error()); Your $id is missing a single quote. mysql_query("UPDATE data SET votes=+1 WHERE id='$id'") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/186016-mysql-error/#findComment-982268 Share on other sites More sharing options...
Twist3d Posted December 22, 2009 Author Share Posted December 22, 2009 mysql_query("UPDATE data SET votes=+1 WHERE id='$id") or die(mysql_error()); Your $id is missing a single quote. mysql_query("UPDATE data SET votes=+1 WHERE id='$id'") or die(mysql_error()); Wow..And i didn't see that lol.. I need to stop wasting Bandwidth lolz. Link to comment https://forums.phpfreaks.com/topic/186016-mysql-error/#findComment-982280 Share on other sites More sharing options...
cags Posted December 22, 2009 Share Posted December 22, 2009 Alternatively you could argue you actually had an extra single quote. Assuming $id is numeric the (')'s aren't required. Link to comment https://forums.phpfreaks.com/topic/186016-mysql-error/#findComment-982287 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.