pro_se Posted July 18, 2006 Share Posted July 18, 2006 [b]Hello... I am trying to create a voting system like digg where you click a link and it adds one in a database... [i]this is what i have so far:[/i][/b] [code]<?mysql_connect("localhost","poop","monkey"); mysql_select_db("funky"); $id = $_GET["id"]; $total_votes = $r['total_votes']; $one = 1; $add = ($total_votes + $one); $sql = "UPDATE links SET total_votes=$add WHERE id=$id"; $result = mysql_query($sql); echo "Plus 1... added...";?>[/code] [u]it does not work... maybe someone can help me?[/u] Link to comment https://forums.phpfreaks.com/topic/14911-adding-with-php-inserting-into-database/ Share on other sites More sharing options...
toplay Posted July 18, 2006 Share Posted July 18, 2006 I don't know where $r['total_votes'] is defined, but if you just want to add one to a column's value, you can simply do:...$sql = "UPDATE links SET total_votes = total_votes + 1 WHERE id='$id'";$result = mysql_query($sql);if (!$result) echo 'Not updated. SQL: ', $sql, ' Error: ', mysql_error();else echo "Plus 1... added..."; Link to comment https://forums.phpfreaks.com/topic/14911-adding-with-php-inserting-into-database/#findComment-59793 Share on other sites More sharing options...
pro_se Posted July 18, 2006 Author Share Posted July 18, 2006 WOW!!! thanks!!!! Link to comment https://forums.phpfreaks.com/topic/14911-adding-with-php-inserting-into-database/#findComment-59798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.