I have a little problem with a basic register script that im writing and i cant seem to be able to fix it.
Well, here is the code:
<?php
//MySQLi connection
$con = mysqli_connect("-","-","-","users");
if (mysqli_connect_errno())
{
echo "MySQLi Connection was not established: " . mysqli_connect_error();
}
//Reading the userdata from the registerp.php page
$usr = mysqli_real_escape_string($con,$_POST['username']);
$email = mysqli_real_escape_string($con,$_POST['email']);
$pass_unhashed = mysqli_real_escape_string($con,$_POST['pass']);
$pass = password_hash($pass_unhashed, PASSWORD_DEFAULT);
//Checking if user exists
$check_usr = mysqli_query($con,"SELECT FROM users WHERE user_name = $usr");
if (mysqli_num_rows($con,$check_usr)>=1)
{
echo "This Username already exists";
}
else
{
echo "This Username is available";
}
?>
Problem is that i cant get the verification (so that people cant register the same name twice) to work:
$check_usr = mysqli_query($con,"SELECT FROM users WHERE user_name = $usr");
if (mysqli_num_rows($con,$check_usr)>=1)
{
echo "This Username already exists";
}
else
{
echo "This Username is available";
}
Always returns "This Username is available", even though the User i used to test it with (nevondrax), is in the MySQL table (thats how it looks like click )
mysqli_query()succeeds, mysqli won't do it for you. Once you do,you'll notice the SQL parse error.