PDA

View Full Version : MySQL Query Question


Lorddraco98
Sun 29th Sep '02, 8:17pm
I'm just learning MySQL/PHP programming here so please bare with me hehe.

I'm coding my website right now, with PHP/MySQL and am working on a login system.
I have already made a page that inserts user data(a registartion page) into the database. So I can use the INSERT into query fine.

I can also successfully check a username/password entered into a form against that of the database using the SELECT * FROM ...WHERE ...

Now I want to do something, to the effect of an admin being able to allow or disallow registartions, by either inserting a 1 or a 0(yes and no on the form) into the database under a colum like "admin approve".

So for this, I'm thinking that I'll have to use a query that takes the data from the databse(either the 0, or the 1 in this case) and puts it into a variable for PHP to use. If this is the right idea to what I have to do, what query, or set of querys/php statements can take data from the database and turn it into a variable??

Also, if this is not the right way to do it, could someone please explain to me how to do this? Thanks!

nsr81
Mon 30th Sep '02, 2:57am
the easiest way to have "admin approve" is to insert a 0 value by default.

INSERT INTO table(id, username, password, approved) VALUES('','$username','$password',0);
Then you can have a page (in an "admin" area), which would list all the unapproved users using a query similar to the following:

SELECT * FROM table WHERE approved=0;
Then you can tell your a PHP script to update the user's status if you wish using the following query (pass id of the desired user in $id variable):

UPDATE table SET approved=1 WHERE id=$id;


This is the main idea. You can also automate the approval, i.e. sending out confirmation emails to the user with activation link in them.

If you need complete example, I'll post some functional PHP code in here.

- Nasir

Lorddraco98
Mon 30th Sep '02, 8:05am
hmm, lemme see if I can get it working without e-mails first hehe, then that'll be the next step, I'll let you know though, thanks!