Jump to content

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...";
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.