PHP MySQL插入数据时出错
如何解决这个问题 可捕获的致命错误:无法捕获类PDO语句的对象 在中转换为字符串 我的PHP代码:PHP MySQL插入数据时出错,php,pdo,Php,Pdo,如何解决这个问题 可捕获的致命错误:无法捕获类PDO语句的对象 在中转换为字符串 我的PHP代码: $a = $_POST['id']; $b = $_POST['title']; $c = $_POST['cat']; $d = $_POST['cop']; $e = $_POST['stat']; $sql = "INSERT INTO books (book_id, book_title, book_category, no_copies, status) VALUES (:a,:b,:
$a = $_POST['id'];
$b = $_POST['title'];
$c = $_POST['cat'];
$d = $_POST['cop'];
$e = $_POST['stat'];
$sql = "INSERT INTO books (book_id, book_title, book_category, no_copies, status) VALUES (:a,:b,:c,:d,:e)";
$a = $db->prepare($sql);
$a->execute(array(':a'=>$a, ':b'=>$b, ':c'=>$c, ':d'=>$d, ':e'=>$e));
header('Location: books.php');
为变量使用有意义的名称($stmt而不是$a,例如,这样可以避免冲突)
您重写变量
$a
$a = $_POST['id']; // assign here
$a = $db->prepare($sql);// override here
试着给一个不同的名字
$smt = $db->prepare($sql);
$smt->execute(array(':a'=>$a,':b'=>$b,':c'=>$c,':d'=>$d,':e'=>$e));
header("location: books.php");
在这里覆盖变量
$a
:$a=$db->prepare($sql)代码>;做一些基本的调试。
$smt = $db->prepare($sql);
$smt->execute(array(':a'=>$a,':b'=>$b,':c'=>$c,':d'=>$d,':e'=>$e));
header("location: books.php");