I’m new to PHP and this is driving me nuts… for some reason, even if the database is empty, whatever username I enter, it tells me the username is already in the database. I also have it checking to see if the same password was written twice, but that is working fine.
Here’s the HTML form:
[code=html]<form action=”registerconfirm.php” method=”POST”>
Username: <input type=”text” name=”username” maxlength=”16″ /><br>
NYU E-mail: <input type=”text” name=”email” /><br>
Password: <input type=”text” name=”pword1″><br>
Password (again): <input type=”text” name=”pword2″><br>
<input type=”submit” value=”Register”>
</form>
Here’s registerconfirm.php (where it checks if same password was typed twice, and if the username exists already in database):
[code=php]<?php
include(“components/scripts.php”);
$username = $_POST[‘username’];
$email = $_POST[’email’];
$pword1 = $_POST[‘pword1’];
$pword2 = $_POST[‘pword2’];
if ($pword1 != $pword2) { // check if passwords match
echo “Passwords do not match. Please re-enter.”;
} else {
dbconnect(); //calls function from “components/scripts.php” to connect to database
$query = “SELECT * FROM users WHERE username=’$username'”; // check if username already exists
$result = mysql_query($query);
if ($result) {
echo “Our database shows this username has already been registered. Please choose another username.”;
} else {
echo “Good”;
}
mysql_close();
}
?>
Anyone know what’s wrong with this code that it’s giving me the “our database shows the username has already been registered” message every time?