Jump to content


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


Adding with php inserting into database?

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]

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


[u]it does not work... maybe someone can help me?[/u]

Share this post

Link to post
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();
    echo "Plus 1... added...";

Share this post

Link to post
Share on other sites


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.