错误
警告:mysqli_query()要求参数1为mysqli,在第22行的E:\ CollegeYear2 \ DesigningAndDevelopingAnInteractiveMediaProduct \ php \ UniServerZ \ www \ WebsiteProject \ ObanScoutsWebsite \ register.php中给出
警告:mysqli_fetch_assoc()要求参数1为mysqli_result,在第23行的E:\ CollegeYear2 \ DesigningAndDevelopingAnInteractiveMediaProduct \ php \ UniServerZ \ www \ WebsiteProject \ ObanScoutsWebsite \ register.php中给出null
警告:mysqli_num_rows()要求参数1为mysqli_result,在第25行的E:\ CollegeYear2 \ DesigningAndDevelopingAnInteractiveMediaProduct \ php \ UniServerZ \ www \ WebsiteProject \ ObanScoutsWebsite \ register.php中给出null
警告:mysqli_query()要求参数1为mysqli,在第34行的E:\ CollegeYear2 \ DesigningAndDevelopingAnInteractiveMediaProduct \ php \ UniServerZ \ www \ WebsiteProject \ ObanScoutsWebsite \ register.php中给出null 有一个问题......
CODE
<?php
require 'connect.inc.php';
$conn = null;
if (isset($_POST['fname']) and isset($_POST['lname'])and isset($_POST['uname'])
and isset($_POST['pwd1'])and isset($_POST['pwd2'])and isset($_POST['email'])
and !empty ($_POST['fname']) and !empty ($_POST['lname']) and !empty ($_POST['uname']) and !empty ($_POST['pwd1'])
and !empty ($_POST['pwd2']) and !empty ($_POST['email'])) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$uname = $_POST['uname'];
$pwd1 = $_POST['pwd1'];
$pwd2 = $_POST['pwd2'];
$email = $_POST['email'];
if ($pwd1 == $pwd2) {
$getinfo = "SELECT * FROM users WHERE uname = '$uname'";
$res = mysqli_query($conn, $getinfo);
$row = mysqli_fetch_assoc($res);
if (mysqli_num_rows($res)>0) {
echo 'User name already taken';
} else {
$pwd1 = PASSWORD_HASH($pwd1, PASSWORD_BCRYPT, array('cost' =>12));
$sql = "INSERT INTO users ( fname, lname, uname, pwd, email ) VALUES('$fname','$lname','$uname','$pwd1','$email')";
if (!mysqli_query($conn, $sql)) {
echo 'There was a problem...';
}else{
header("Location: index.php");
}
}
}else{
echo 'Your passwords didn\'t match';
}
}
?>
<h3>Please Register</h3>
<h4><?php echo $conn; ?></h4>
<form action="register.php" method="POST">
<input type="text" name="fname" placeholder="First Name"><br>
<input type="text" name="lname" placeholder="Last Name"><br>
<input type="text" name="uname" placeholder="User Name"><br>
<input type="password" name="pwd1" placeholder="Password"><br>
<input type="password" name="pwd2" placeholder="Re-enter Password"><br>
<input type="email" name="email" placeholder="E-mail"><br><br>
<input type="submit">
答案 0 :(得分:0)
mysqli_query() expects parameter 1 to be mysqli, null given
表示您尚未连接到数据库。检查您与数据库的连接(如果用户名和密码正确且与数据库相同)