我正尝试使用如下准备语句插入以下查询,但是无法添加。以下是代码:
$name=$_POST['text_name'];
$rn=$_POST['text_rn'];
$email=$_POST['email'];
$gender=$_POST['gender'];
$upass= password_hash($_POST['text_pass'], PASSWORD_DEFAULT);
$addrec = $conn->prepare("INSERT INTO students(name,rollno,password,gender,email) VALUES (?,?,?,?,?)");
$addrec->bind_param("sssss",$name,$rollno,$password,$gender,$email);
if($addrec->execute()){
echo "<div class='w3-panel w3-green w3-display-container' style='width:40%;'>
<span onclick='this.parentElement.style.display='none''
class='w3-button w3-large w3-display-topright'>×</span>
<p>New record created successfully</p>
</div>";
}
else
echo "<div class='w3-panel w3-red w3-display-container' style='width:40%;'>
<span onclick='this.parentElement.style.display='none''
class='w3-button w3-large w3-display-topright'>×</span>
<p>Record not added</p>
</div>";
代码非常简单,但显示的是“未添加记录”,这是else
的情况。以下是我的表结构。
+------------------+---------------+-------+------+--------------------+----------------+--+
| Field | Type | Null | Key | Default | Extra | |
+------------------+---------------+-------+------+--------------------+----------------+--+
| id | int(11) | NO | PRI | NULL | auto_increment | |
| name | varchar(200) | NO | | NULL | | |
| email | varchar(200) | NO | | NA | | |
| password | text | NO | | NULL | | |
| gender | varchar(6) | NO | | NULL | | |
| rollno | int(255) | NO | | NULL | | |
| image | varchar(255) | NO | | default-pic.png | | |
| personal_notice | varchar(500) | NO | | Not Available Yet | | |
+------------------+---------------+-------+------+--------------------+----------------+--+
可能是什么问题?请帮忙。
答案 0 :(得分:0)
$rollno
中的 $addrec->bind_param("sssss",$name,$rollno,$password,$gender,$email);
应该是$rn
并且$password
应该是$upass