警告:mysqli_num_rows()要求参数1为mysqli_result,在第30行的/home/a4664388/public_html/index.php中给出为null
警告:mysqli_query()要求参数1为mysqli,第32行/home/a4664388/public_html/index.php中给出的字符串
警告:mysqli_num_rows()要求参数1为mysqli_result,在第35行的/home/a4664388/public_html/index.php中给出null
警告:mysqli_query()要求参数1为mysqli,第57行/home/a4664388/public_html/index.php中给出的字符串
我的代码是以下
<?php include_once("inc/header.php");
?>
<?php
$reg = @$_POST['reg'];
//declaring variables to prevent errors
$fn = ""; //First Name
$ln = ""; //Last Name
$un = ""; //Username
$em = ""; //Email
$em2 = ""; //Email 2
$pswd = ""; //Password
$pswd2 = ""; // Password 2
$d = ""; // 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) {
// Check if user already exists
$u_check = mysqli_query($link = "SELECT Username FROM users WHERE Username=`$un`");
// Count the amount of rows where username = $un
$check = mysqli_num_rows($u_check);
//Check whether Email already exists in the database
mysqli_query($link, "SELECT email FROM users WHERE email = '$em' ");
// ^ first parameter, the mysqli connection object
//Count the number of rows returned
$email_check = mysqli_num_rows($e_check);
if ($check == 0) {
if ($email_check == 0) {
//check all of the fields have been filed 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 the maximum length of password does not exceed 25 characters and is not less than 5 characters
if (strlen($pswd)>30||strlen($pswd)<5) {
echo "Your password must be between 5 and 30 characters long!";
}
else
{
//encrypt password and password 2 using md5 before sending to database
$pswd = md5($pswd);
$pswd2 = md5($pswd2);
$query = mysqli_query($link, "INSERT INTO users VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0','Write something about yourself.','','','no')");
die("<h2>Welcome to futurzLife</h2>Login to your account to get started ...");
}
}
}
else {
echo "Your passwords don't match!";
}
}
else
{
echo "Please fill in all of the fields";
}
}
else
{
echo "Sorry, but it looks like someone has already used that email!";
}
}
else
{
echo "Username already taken ...";
}
}
else {
echo "Your E-mails don't match!";
}
}
?>
<link rel="stylesheet" type="text/css" href="./css/style.css" />
<div style="width: 800px; margin: 0px auto 0px auto;">
<table>
<tr>
<td width="60%" valign="top">
<h2>Join FuturzLife Today!</h2>
</td>
<td width="40%" valign="top">
<h2>Sign Up Below!</h2>
<form action="#" method="POST">
<input type="text" name="fname" size="25" placeholder="First Name" /><br /><br />
<input type="text" name="lname" size="25" placeholder="Last Name" /><br /><br />
<input type="text" name="username" size="25" placeholder="User Name" /><br /><br />
<input type="text" name="email" size="25" placeholder="Email Address" /><br /><br />
<input type="text" name="email2" size="25" placeholder="Email Address (Again)" /><br /><br />
<input type="text" name="password" size="25" placeholder="Password" /><br /><br />
<input type="text" name="password2" size="25" placeholder="Password (Again)" /><br /><br />
<input type="submit" name="reg" value="Sign Up!" placeholder="First Name" /><br /><br />
</form>
</td>
</tr>
</table>
<?php include_once ("inc/footer.php"); ?>
答案 0 :(得分:1)
看看这一行:
$u_check = mysqli_query($link = "SELECT Username FROM users WHERE Username=`$un`");
您要将字符串分配给$link
可能你的意思是,
而不是=
此外,您不应该在查询中对值进行反引号。
<强>调试/故障排除:强>
将or die(mysqli_error($link))
添加到mysqli_query()
,包括error reporting,以便对代码进行故障排除/调试。