Jump to content


Photo

Adding with php inserting into database?


  • Please log in to reply
2 replies to this topic

#1 pro_se

pro_se
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 18 July 2006 - 05:08 AM

Hello... I am trying to create a voting system like digg where you click a link and it adds one in a database... this is what i have so far:

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

?>


it does not work... maybe someone can help me?

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 18 July 2006 - 05:26 AM

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


#3 pro_se

pro_se
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 18 July 2006 - 05:59 AM

WOW!!! thanks!!!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users