Php PDOException:SQLSTATE[HY093]:无效参数编号:未定义参数
请帮我解决不了,试了三天却不知道是什么原因把这样的消息扔给了我。(以下是我的完整代码)Php PDOException:SQLSTATE[HY093]:无效参数编号:未定义参数,php,html,css,pdo,Php,Html,Css,Pdo,请帮我解决不了,试了三天却不知道是什么原因把这样的消息扔给了我。(以下是我的完整代码) 插入新员额 在此插入新帖子 职位名称: 文章作者: 张贴图片: 帖子内容: 上述表格用于在数据库中插入和提交数据 // PHP <?php include("includes/connect.php"); if (isset($_POST['submit'])) { $title = $_POST['title']; $datenow = date('Y/m/d');
插入新员额
在此插入新帖子
职位名称:
文章作者:
张贴图片:
帖子内容:
上述表格用于在数据库中插入和提交数据
// PHP
<?php
include("includes/connect.php");
if (isset($_POST['submit'])) {
$title = $_POST['title'];
$datenow = date('Y/m/d');
$author = $_POST['author'];
$content = $_POST['content'];
$image_name = $_FILES['image_name']['name'];
$image_type = $_FILES['image_name']['type'];
$image_size = $_FILES['image_name']['size'];
$image_tmp = $_FILES['image_name']['tmp_name'];
if ($title =='' || $author =='' || $content =='') {
echo "<script>alert('Any feild is empty')</script>";
exit();
}
if ($image_type =='image/jpeg' || $image_type =='image/png' || $image_type =='image/gif') {
if ($image_size<=5000000000) {
move_uploaded_file($image_tmp, "images/$image_name");
}
else{
echo "<script>alert('Image is larger, only 50kb size is allowed') </script>";
}
}
else{
echo "<script>alert('image type is invalid')</script>";
}
// insert query
$sth = $con->prepare(" INSERT INTO posts (post_title, post_date, post_author, post_image, post_content) VALUE (:title,:datenow,:author,:image_name,:content) ");
$sth->bindParam(':post_title', $title);
$sth->bindParam(':post_date', $datenow);
$sth->bindParam(':post_author', $author);
$sth->bindParam(':post_image', $image_name);
$sth->bindParam(':post_content', $content);
$sth->execute();
echo "<h1>Form Submited Successfully</h1>";
}
?>
// $sth->execute(); is throwing error massage as above
//PHP
您绑定了错误的值。您没有绑定post_*值。见下文:
$sth = $con->prepare(" INSERT INTO posts (post_title, post_date, post_author, post_image, post_content) VALUES (:post_title,:post_date,:post_author,:post_image,:post_content) ");
$sth->bindParam(':post_title', $title);
$sth->bindParam(':post_date', $datenow);
$sth->bindParam(':post_author', $author);
$sth->bindParam(':post_image', $image_name);
$sth->bindParam(':post_content', $content);
您正在绑定:title,:datenow,:author..
而不是:post\u title,:post\u date..
谢谢。我很高兴能帮助您。
$sth = $con->prepare(" INSERT INTO posts (post_title, post_date, post_author, post_image, post_content) VALUES (:post_title,:post_date,:post_author,:post_image,:post_content) ");
$sth->bindParam(':post_title', $title);
$sth->bindParam(':post_date', $datenow);
$sth->bindParam(':post_author', $author);
$sth->bindParam(':post_image', $image_name);
$sth->bindParam(':post_content', $content);