-2
我有一個問題,我似乎無法用我的註冊腳本來解決。MySQL&PHP,mysqli_num_rows總是返回0
這裏的腳本:
<?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(check_usr === false)
{
echo(mysqli_error($con));
}
else
{
if (mysqli_num_rows($con,$check_usr)>=1)
{
echo "This Username already exists";
}
else
{
echo "This Username is available";
echo " Name: $usr";
}
}
?>
我的問題是,我無法得到驗證工作(這樣他們不能創建兩個帳戶使用相同的名稱)。
mysqli_num_rows
總是返回0(「這個用戶名可用」)即使是在我table
而且我的測試用戶(nevondrax),它似乎並沒有給我任何錯誤,要麼..
我做錯了什麼/我能做些什麼來解決它?
不通過連接' mysqli_num_rows'只需使用它作爲'mysqli_num_rows($ check_usr)' – Saty
非常感謝,我一直在尋找小時和小時,並找不到錯誤......好吧,現在它的工作! – Nevondrax
那麼你的腳本是打開的SQL注入閱讀http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1,以防止它 – Saty