Jump to content

Adding with php inserting into database?


pro_se

Recommended Posts

[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

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...";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.