Jump to content


Mysql UPDATE wont work..


2 replies to this topic

#1 derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 341 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

Posted 21 June 2008 - 05:26 PM

$v = $fetch['view'];
$add = 1;
$insert = $v + $add;
mysql_query("UPDATE `tutorials` SET `views` = '$insert' WHERE `id` = '$id'") or die("MySql Error 3: ".mysql_error()." in tutorial");

any help? I can't see why it wont work...

let me add some detail lol. I have the default set as 0 so $v would = 0 and $add = 1.. so it should go 0 + 1 and it works for the first view, it'll update but online 1 time? Every other time i view the tutorial, it wont update at all and it's bugging me...

Edited by bigdfbc2008, 21 June 2008 - 05:28 PM.


#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 21 June 2008 - 09:51 PM

Typo aside, you should use the following. It does what you want with 1 query and 1 line :rolleyes:
mysql_query("UPDATE `tutorials` SET `views` = `views`+1 WHERE `id` = '$id'") or die("MySql Error 3: ".mysql_error()." in tutorial");

p.s. You're missing an 's'
$v = $fetch['view'];

Edited by rc69, 21 June 2008 - 09:51 PM.


#3 derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 341 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

Posted 22 June 2008 - 02:44 PM

View Postrc69, on Jun 21 2008, 10:51 PM, said:

Typo aside, you should use the following. It does what you want with 1 query and 1 line :)
mysql_query("UPDATE `tutorials` SET `views` = `views`+1 WHERE `id` = '$id'") or die("MySql Error 3: ".mysql_error()." in tutorial");

p.s. You're missing an 's'
$v = $fetch['view'];


Thank you!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users