好吧,所以我想添加一個用戶註冊表單到我的網站。我一直試圖解決這個問題好幾天沒有我已經試過似乎在工作的時候填寫登記表目前我得到這個警告並點擊提交按鈕一直在看這個好幾天,不知道。 「警告:mysql_num_rows()期望參數1是資源,布爾給出
警告:。mysql_num_rows()預計參數1是資源,在/應用空給出/ XAMPP/xamppfiles/htdocs目錄/tutorials/MySite/index.php on line 64
我有三重檢查,以確保我的數據庫和行的語法在腳本和phpmyadmin中是相同的,所以我真的失去了,沒有從這裏知道該怎麼做,我總是遇到連接和做查詢的麻煩s /從phpmyadmin中檢索信息。
到目前爲止,這是我已經得到了(對不起了這麼多的代碼):
<?php
$reg = $_POST['reg'];
// declaring variables to prevent errors
$fn = ""; //first name
$ln = ""; //last name
$un = ""; //username
$em = ""; //email
$em2 = ""; //email 2
$pswd = ""; //sign up date
$u_check = ""; //check if username exists
//registration form
$fn = strip_tags($_POST['fname']);
$ln = strip_tags($_POST['lname']);
$un = strip_tags($_POST['username']);
$em = strip_tags($_POST['email']);
$em2 = strip_tags($_POST['email2']);
$pswd = strip_tags($_POST['password']);
$pswd2 = strip_tags($_POST['password2']);
$d = date("Y-m-d"); // year - month - day
if ($reg) {
if ($em == $em2) { //this block of code is where I'm having the most trouble at.
// Check if user already exists
$u_check = mysql_query("'SELECT' username 'FROM' users 'WHERE' username='$un'");
// Count the amount of rows where username= $un
$check = mysql_num_rows($u_check); //<<<<<<<<<<<<<<<<<<<<<<<<LINE 64
if ($check == 0) { //maybe this should be $u_check??\\
//check all of the fileds have been filled in
if ($fn && $ln && $un && $em && $em2 && $pswd && $pswd2) {
//check that passwords match
if ($pswd == $pswd2) {
//check the maximum length of username/first name/last name does not exceed 25 characters.
if (strlen($un) > 25 || strlen($fn) > 25 || strlen($ln) > 25) {
echo "The maximum limit for username/first name/ last name is 25 characters!";
} else { //check to see if password is allowable length
if (strlen($pswd) > 30 || strlen($pswd) < 5) {
echo "Your password must be between 5 and 30 characthers long!";
} else {
//encrypts password using md5 before sending to database
$pswd = md5($pswd);
$pswd2 = md5($pswd2);
$query = mysql_query("INSERT INTO users VALUES (' ', '$un', '$fn', '$ln', '$em', '$pswd', '$d', '0')");
die("<h2>Welcome to MySite</h2>Login to your account to get started....");
}
}
} else {
echo "Your passwords don't match!";
}
} else {
echo "Please fill in all fields";
}
}
}
}
?>
再次,我一直試圖讓這個固定的日子,但還是無法弄清楚什麼是繼續。
'strip_tags'不望其項背[適當的SQL逃逸(http://bobby-tables.com/php)。如果你寫這個,你真的需要[刷新基本知識](http://biasedphp.com/php-commandments)。你在這裏建立的應用程序是什麼?你不能存儲純文本密碼,並認爲沒關係。 – tadman
-1爲2013年使用mysql_query。嘗試[mysqli](http://us1.php.net/manual/en/book.mysqli.php)或[PDO](http://us1.php.net/manual改爲/en/book.pdo.php)。 – cHao