pcw Posted March 15, 2011 Share Posted March 15, 2011 Hi, I got this script which checks a username does not exist, before writing the users registration info to the database. It was working fine, but now for some reason says there is a duplicate username in the database, when there isnt <?php $password1 = $_POST['password1']; $password2 = $_POST['password2']; if ($password1 != $password2) { echo "Your passwords did not match, please go back and register again"; } else { // Check Passwords Match // Get Posted Variables $username = $_POST['username']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $address = $_POST['address']; $town = $_POST['town']; $county = $_POST['county']; $postcode = $_POST['postcode']; $email = $_POST['email']; $approved = "no"; // MySQL Connection include_once("data/mysql.php"); $mysqlPassword = (base64_decode($mysqlpword)); $con = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die(mysql_error()); mysql_select_db("$dbname", $con) or die(mysql_error()); $query = "SELECT COUNT(*) AS count FROM members WHERE username='$username'"; $results = mysql_query($query) or die ("Error reading from database"); $existingUsername = mysql_fetch_array($results); if ($existingUsername['count'] > 0) { echo "I'm sorry our database already contains that username please choose a new username to continue."; } else { $sql = "INSERT INTO members (username, firstname, lastname, address, town, county, postcode, email, password, approved) VALUES ('$_POST[username]','$_POST[firstname]','$_POST[lastname]','$_POST[address]','$_POST[town]','$_POST[county]','$_POST[postcode]','$_POST[email]','$_POST[password2]','$approved')"; mysql_query($sql,$con); ?> <meta http-equiv="REFRESH" content="5;url=../login.html"> <?php } mysql_close($con); } ?> Im sure it is something simple, I just cant see what it is. As always, any help is much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/230738-non-existent-duplicate-error/ Share on other sites More sharing options...
Maq Posted March 15, 2011 Share Posted March 15, 2011 EDIT: What's the exact error message? I assumed you were referring to this line: echo "I'm sorry our database already contains that username please choose a new username to continue."; Echo out $query to make sure the username you expect is actually being queried with. If not, we would need to see your HTML form, maybe the name is different. Quote Link to comment https://forums.phpfreaks.com/topic/230738-non-existent-duplicate-error/#findComment-1187902 Share on other sites More sharing options...
pcw Posted March 15, 2011 Author Share Posted March 15, 2011 Hi Maq, thanks for your reply. It turned out I was just being a dope and forgot to put method=post in the form action line. Never mind lol Quote Link to comment https://forums.phpfreaks.com/topic/230738-non-existent-duplicate-error/#findComment-1187924 Share on other sites More sharing options...
Maq Posted March 15, 2011 Share Posted March 15, 2011 Hi Maq, thanks for your reply. It turned out I was just being a dope and forgot to put method=post in the form action line. Never mind lol Gotcha, glad it's solved. Quote Link to comment https://forums.phpfreaks.com/topic/230738-non-existent-duplicate-error/#findComment-1187927 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.