0

I am trying to create a query which will update each person's profile views when a member accesses their profile. For some reason it does not update, I am sure it would have worked. Here is my lines:

<?php
$name = $_REQUEST['username'];
$profile = mysql_query("SELECT * FROM users WHERE user_name='$name'");
$uprofile = mysql_fetch_assoc($profile);

$username = $uprofile['user_name'];
$profilev = $uprofile['profile_views'];

mysql_query("UPDATE users SET profile_views +1 WHERE user_name='$name'");

?>

So, On my profile, It displays their username successfully, and it displays the default value of the database for profile_views which ofcourse, is 0. so it is reading correctly, I am just having issues updating the users profile_views.

Joe Bills
  • 31
  • 5
  • 1
    `SET profile_views = profile_views+1 WHERE` But you should better stop using deprecated `mysql*` functions – Alex Apr 29 '16 at 19:50
  • Thank you, but just because its depreated, why should i not use it? i don't really know anything about PDO – Joe Bills Apr 29 '16 at 20:04
  • just read some there http://stackoverflow.com/a/12860046/4421474 – Alex Apr 29 '16 at 20:05

1 Answers1

3

You have a mistake try

"UPDATE users 
 SET profile_views = profile_views  +1 
 WHERE user_name='$name'"
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • Thank you. Is there a way I could also limit it so to if the same user re-visits the other members page, it would not update again for like, 24 hours? – Joe Bills Apr 29 '16 at 20:08
  • You should store a realtion between user and visitors with the dae of last visist the check fo this date before perform the increment of visit.. – ScaisEdge Apr 29 '16 at 20:11
  • 1
    Why should the OP "try" this? A ***good answer*** will always have an explanation of what was done and why it was done in such a manner, not only for the OP but for future visitors to SO. – Jay Blanchard Apr 29 '16 at 21:33