Page 1 of 1

CONFUSED

Posted: Sun Aug 19, 2007 4:04 pm
by duffy
in a form, how can you make it so that if someone puts in an invalid account (example to private message someone in a forum) it says: Sorry, This account is invalid.

Re: CONFUSED

Posted: Sun Aug 19, 2007 4:18 pm
by Chris Corbyn
duffy wrote:in a form, how can you make it so that if someone puts in an invalid account (example to private message someone in a forum) it says: Sorry, This account is invalid.
You have to query the database when the form is submitted. The form has an "action" attribut which points to a PHP file. That PHP file looks what username was requested then builds a SELECT query for the database:

Code: Select all

select id from users where username = '$username'
(Remember to use mysql_real_escape_string() if you're using MySQL).

All you have to do is check whether any rows are returned or not. If none are returned you redirect back to the form with something like form.php?error=no_such_user. You can use the header() function to do the redirect ;)