html表单运行.php错误问题 5C

表单提交后运行老出现警告信息,这是什么问题啊
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in D:\phpStudy\WWW\FunPic\txet\04\addBook.php on line 19

Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in D:\phpStudy\WWW\FunPic\txet\04\addBook.php on line 21

Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, boolean given in D:\phpStudy\WWW\FunPic\txet\04\addBook.php on line 22
添加失败

代码:
<?php
//连接数据库
$link = mysqli_connect('localhost','root','root','db_users');
if(!$link){
die('连接失败:'.mysqli_connect_errno());
}
//接收数据
$name = $_POST['name'];
$category =$_POST['category'];
$price =$_POST['price'];
$publish_time =$_POST['publish_time'];

//插入数据库
$sql = "insert into tb_users(name,category,price,publish_time) values(?,?,?,?)";
/*$stmt = mysqli_query($link,$sql);*/
//预处理
$stmt = mysqli_prepare($link,$sql);
//绑定参数
mysqli_stmt_bind_param($stmt,'ssds',$name,$category,$price,$pubilsh_time);
//执行SQL语句
mysqli_stmt_execute($stmt);
if(mysqli_stmt_affected_rows($stmt)){
echo"alert(&#39;添加成功&#39;);window.location.href=&#39;index.php&#39;<script>&quot;;<br> }else{<br> echo&quot;添加失败&quot;;<br> }</p>

0

2个回答

0
weixin_43962397
SKY陈 全英文,看不懂,麻烦中文解释一下,谢谢!
7 个月之前 回复
 $sql = "insert into tb_users(name,category,price,publish_time) values(?,?,?,?)";

这其中的字段name需要用反引号括起来,写成:

 $sql = "insert into tb_users (`name`,category,price,publish_time) values (?,?,?,?)";
0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!