表单提交后运行老出现警告信息,这是什么问题啊
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('添加成功');window.location.href='index.php'<script>";<br>
}else{<br>
echo"添加失败";<br>
}</p>