更新2:我已经通过我自己解决了这个问题,如果我记得很清楚,代码如下:解析为正确的格式。 更新:我找到了错误,我现在得到的最后一件事就是这个 我将使用正确的预览错误发布回复。
致命错误:带有消息的未捕获异常'PDOException' 'SQLSTATE [42S22]:未找到列:1054未知列'标题' C:\ xampp \ htdocs \ Final \ include \ add_blog.php中的'字段列表':56堆栈 trace:#0 C:\ xampp \ htdocs \ Final \ include \ add_blog.php(56): PDOStatement-> execute()#1 C:\ xampp \ htdocs \ Final \ addblog.php(194): require('C:\ xampp \ htdocs ...')#2 {main}引入 第56行的C:\ xampp \ htdocs \ Final \ include \ add_blog.php
我正在尝试将以下数据插入数据库。但由于某种原因我得到了未定义的索引,即使我已经检查过并且两个变量里面都有值,你能用新的眼光看看它吗? (自定义我的添加用户代码) 错误代码
注意:未定义的索引:用户输入 第53行的C:\ xampp \ htdocs \ Final \ include \ add_blog.php
注意:未定义的索引:中的类别 第56行的C:\ xampp \ htdocs \ Final \ include \ add_blog.php
致命错误:带有消息的未捕获异常'PDOException' 'SQLSTATE [42S22]:未找到列:1054未知列'标题' C:\ xampp \ htdocs \ Final \ include \ add_blog.php中的'字段列表':57堆栈 trace:#0 C:\ xampp \ htdocs \ Final \ include \ add_blog.php(57): PDOStatement-> execute()#1 C:\ xampp \ htdocs \ Final \ addblog.php(194): require('C:\ xampp \ htdocs ...')#2 {main}引入 第57行的C:\ xampp \ htdocs \ Final \ include \ add_blog.php
我的代码
<?php
try {
require SITE_ROOT . '\include\db_connect.php';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
$title = $_POST['title'];
$user = $_SESSION['username'];
$description = $_POST['description'];
$content = $_POST['content'];
$categories = "Basic";
//verifications
//password
if (empty($title) || empty($user) || empty($description) || empty($content) || empty($categories)){
$error = "Complete all fields";
}
if (strlen($content) == 30){
$error = "Please Input some More content into your blog";
}
if(!isset($error)){
//Securly insert into database
$sql = 'INSERT INTO blogusers (title,user,description,content,categories) VALUES (:title,:user,:description,:content,:categories)';
$stmt = $conn->prepare($sql);
$stmt->bindParam(':title',$title);
$stmt->bindParam(':user',$user);
$stmt->bindParam(':description',$description);
$stmt->bindParam(':content',$content);
$stmt->bindParam(':categories',$categories);
$title = $_POST['title'];
$user = $_POST['user'];
$description = $_POST['description'];
$content = $_POST['content'];
$categories = $_POST['categories'];
$stmt->execute();
echo "<div class='alert alert-success alert-dismissible' role='alert' id='alert-top'>" ;
echo " <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>" ;
echo " <strong>Success!</strong> " .$_POST['title']. " , Has been created" ;
echo "</div> ";
}else{
echo "<div class='alert alert-danger alert-dismissible' role='alert' id='alert-top'>" ;
echo " <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>" ;
echo " <strong>Warning!</strong> " .$error ;
echo "</div> ";
exit();
}
?>