I tried reading some of other answers on this issue, but none of them are really answering everything, and I'm not even sure if this would be the best way to do it anymore.
What I'm trying to do here is to check if username exists and if password matches the second password entry. it all worked fine before testing if the username already existed, and in some other forms it actually works, so I believe I'm mixing mysqli
and mysql
functions, but I'm not sure which ones, please help me guys :)
$conn = mysql_connect("localhost", "root", "password") or die (mysql_error());
mysql_select_db("Accounts") or die (mysql_error());
$checkusername = mysql_query("SELECT * FROM users2 WHERE username = '$username'") or die (mysql_error());
$count = mysql_num_rows($checkusername);
if (($password === $passwordTest) && ($count == 0)){
$sql = "INSERT INTO users2 (Username, Password, First, Last)
VALUES ('$username', '$password', '$firstName', '$lastName')";
if ($conn->query($sql) === TRUE) {
echo "Data inserted successfully";
}
else {
echo "Error creating Account: " . $conn->error;
}
}
elseif ($password != $passwordTest){
echo "Password not matching.";
}
if ($count > 0){
echo "Username already exists.";
}
the error says the mistake is here:
if ($conn->query($sql) === TRUE)