Reaper0167 Posted January 15, 2009 Share Posted January 15, 2009 here is my reg script...every works good except for giving an error if the username or email already exists. i can't seem to find the problem. <?php // connection to your database include ("connection.php"); // connects to server and database mysql_connect("$host", "$username", "$password") or die("Could not connect."); mysql_select_db("$db_name") or die("Could not find database"); // define variables from form register form $username = mysql_real_escape_string($_POST["username"]); $password = md5($_POST["password"]); $email = mysql_real_escape_string($_POST["email"]); // check if username/email is already registered, if so, give error message $sql="SELECT * FROM $tbl_name WHERE username = '$username' and email = '$email' LIMIT 1"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count == 1) { session_start(); $_SESSION['message'] = "The username and/or password is also registered. Please try again."; header("location: registration.php"); } // insert user into database $sql = "INSERT INTO $tbl_name(username, password, email)VALUES('$username','$password','$email')"; mysql_query($sql) or die(mysql_error()); // direct user to login page with a succuess message session_start(); $_SESSION['message'] = "Thank you for registering $username. You may now log in."; header("location: http://www.------------.com"); // closes your connection mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted January 15, 2009 Share Posted January 15, 2009 What exactly is the problem? Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted January 15, 2009 Author Share Posted January 15, 2009 oh sorry....when i try to register a username and/or email that already exists in the database, it lets me register that name.. i would like it to give me an error saying that it already exists. Quote Link to comment Share on other sites More sharing options...
trq Posted January 15, 2009 Share Posted January 15, 2009 You need to put an exit() after calls to header otherwise the script will continue processing. Otherwise, I don't see any reason that code won't work. Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted January 15, 2009 Author Share Posted January 15, 2009 thank you,, i fixed it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.