Hi all, Im looking for some help with a profile view counter in php.
What im trying to do is update mysql db by 1 everytime a profile is viewed.
ATM when a profile is viewed, my db is updating every profile by 1
please review my code below and point me in the right direction as to where i am going wrong.
//update profile views//
$sql="SELECT * FROM memberst WHERE id='".$_SESSION['id']."'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
$counter=$rows['counter'];
// if have no counter value set counter = 1
if(empty($counter)){
$counter=1;
$sql1="INSERT INTO memberst(counter) WHERE id='$id' VALUES('$counter')";
$result1=mysql_query($sql1);
}
// count more value
$addcounter=$counter+1;
$sql2="update memberst set counter='$addcounter'";
$result2=mysql_query($sql2);
//end of update views//
cheers,