Unique Users

Okay so I’ve come upon a really odd issue that I can’t figure out. I created a VARIABLE in my database that I called “posted”. Now I want it so that when someone posts on the page, it sets to 1. I will be making it so that if it’s set to one they cannot post anymore. Now… my problem is that my code sets it to 1 for all the users when someone posts.

FOR EXAMPLE.
I go on the website and post and the variable sets to 1 for all the registered users… So now no one can post!? The code I have created so far…:

[php] $gettop = mysql_query(“SELECT * FROM users”);
while($therow = mysql_fetch_assoc($gettop)) {

                        $id = $therow['id'];

                        mysql_query("UPDATE users SET posted = 1 WHERE id = '$id'"); 

                    }[/php]

THANKS IN ADVANCE

First you’re using obsolete mysql, you should be using mysqli or PDO (My Recommendation). Second, I have now idea what you really are asking for? (Maybe someone else does?)

In your code you are selecting all users

Then for each user you set posted = 1

So no wonder you get the result you are experiencing, it’s exactly what you have implemented :wink:

[hr]

I guess you want something like this

on login you set $_SESSION[‘user’] or $_SESSION[‘userId’]

then you can easily do this instead of what you have now

[php]mysql_query(“UPDATE users SET posted = 1 WHERE id = ‘$_SESSION[‘userId’]’”);[/php]

[hr]

And yes, as Strider points out you should update your code to not use the obsolete mysql_* api

Sponsor our Newsletter | Privacy Policy | Terms of Service