我正在开展一个学校项目,当我试图创建一个具有注册功能的网站时,我在提交表单后会显示此错误:
致命错误:未捕获错误:在/storage/ssd5/928/6222928/public_html/04_Registration.php:34中调用boolean上的成员函数bind_param()堆栈跟踪:/ storage / ssd5中抛出#0 {main}第34行/928/6222928/public_html/04_Registration.php
<!DOCTYPE HTML>
<html>
<head>
<title>Register Form</title>
</head>
<body>
<form action="04_Registration.php" method="POST">
<table>
<tr>
<td>Name :</td>
<td><input type="text" name="username" required></td>
</tr>
<tr>
<td>Password :</td>
<td><input type="password" name="password" required></td>
</tr>
<tr>
<td>TP Number :</td>
<td><input type="text" name="tpnumber"></td>
</tr>
<tr>
<td>Gender :</td>
<td>
<input type="radio" name="gender" value="m" required> Male
<input type="radio" name="gender" value="f" required> Female
</td>
</tr>
<tr>
<td>Group :</td>
<td>
<input type="radio" name="group" value="a" required> A
<input type="radio" name="group" value="b" required> B
</td>
</tr>
<tr>
<td>Email :</td>
<td><input type="email" name="email" required placeholder="TP011111@mail.apu.edu.my"></td>
</tr>
<tr>
<td>Phone no :</td>
<td>
<select name="phoneCode" required>
<option selected hidden value="">Select code</option>
<option value="011">011</option>
<option value="012">012</option>
<option value="016">016</option>
<option value="017">017</option>
<option value="018">018</option>
<option value="019">019</option>
</select>
<input type="phone" name="phone" required placeholder="017460****">
</td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$tpnumber = $_POST['tpnumber'];
$gender = $_POST['gender'];
$group = $_POST['group'];
$email = $_POST['email'];
$phoneCode = $_POST['phoneCode'];
$phone = $_POST['phone'];
if (!empty($username) || !empty($password) || !empty($tpnumber) || !empty($gender) || !empty($group) || !empty($email) ||
!empty($phoneCode) || !empty($phone)) {
$host = "localhost";
$dbUsername = "id6222928_apuassignment2018";
$dbPassword = "joeshern123";
$dbName = "id6222928_registered";
//create connection
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbName);
if (mysqli_connect_error()) {
die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
} else {
$SELECT = "SELECT email From users Where email = ? Limit 1";
$INSERT = "INSERT Into users (username, password, tpnumber, gender, group, email, phoneCode, phone) values(?, ?, ?, ?, ?, ?, ?, ?)";
//Prepare statement
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($email);
$stmt->store_result();
$rnum = $stmt->num_rows;
if ($rnum==0) {
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("ssssssii", $username, $password, $tpnumber, $gender, $group, $email, $phoneCode, $phone);
$stmt->execute();
echo "Registration success!!";
} else {
echo "Someone already register using this email";
}
$stmt->close();
$conn->close();
}
} else {
echo "All field are required";
die();
}
?>
答案 0 :(得分:0)
尝试更改此内容:
bind_param("ssssssii", $username, $password, $tpnumber, $gender, $group, $email, $phoneCode, $phone);
到此:
bind_param($username, $password, $tpnumber, $gender, $group, $email, $phoneCode, $phone);
答案 1 :(得分:0)
首先,希望您正在按预期通过XAMPP运行该程序。
通常,由于与数据库关联的代码而发生此问题
也许您在phpmyadmin中创建的列名与您要触发的列名不同,也许错误会与columnNames或tableName的拼写一样少,
尝试检查相同内容或进行一些调整。