Can someone steer me in the right direction?, On my form, once the user has entered his information and pressed the "Save" button i want my code to check if that name already exists, and if it does spit out a message and if it doesn't then add the new user.
This is where i would like to insert that piece of code:
[syntax=php]if ($_POST['button'] == 'Save') {
$query = "INSERT INTO clientinfo (client_id, contact_name, position, department, street, city, prov_state, country, zip_postal, phNumber, faxNumber, pagerNumber, email) VALUES '$client_id', '$contact_name', '$position', '$department', '$street', '$city', '$prov_state', '$country', '$zip_postal', '$phNumber', '$faxNumber', '$pagerNumber', '$email');";
}[/syntax]
Thnx
Checking duplicate users
Moderator: General Moderators
or:
Code: Select all
$query = "INSERT INTO table (id, name, address) VALUES($id, '$name', '$address') WHERE name <> '$name'";
if (!$result = mysql_query($query)) {
echo "Username taken";
}yes, the query will fail if the user exists. However, if there is any problem with the query - say, for example, the table structure changes - the script will return "user already exists" which is untrue. This can make debugging a royal pain the the butt later, when your program gives you an untrue error message - because you told it to.