CONFUSED

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
duffy
Forum Newbie
Posts: 19
Joined: Wed Aug 08, 2007 4:20 pm

CONFUSED

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: CONFUSED

Post 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 ;)
Post Reply