gpt4 book ai didi

php - 当记录没有插入(准备好的语句)时,为什么我没有在 PHP 中收到错误?

转载 作者:搜寻专家 更新时间:2023-10-31 21:47:27 25 4
gpt4 key购买 nike

好的,这就是我想要做的。我正在向我的数据库中插入一些数据。这是一个博客,我有作者、标签、隐藏元标签等字段。几周来我一直在努力解决这个问题。本质上,我在我的 CMS 上,似乎没有插入任何内容,但我没有收到任何错误(即使使用 error_reporting( E_ALL ); 强制执行)。据我所知,所有内容都以正确的顺序使用正确的变量提交下面是我的代码,感谢您的帮助!

HTML:

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Admin Panel</title>
<link rel="stylesheet" href="../css/master.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tag-editor/1.0.20/jquery.tag-editor.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tag-editor/1.0.20/jquery.tag-editor.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jodit/3.2.34/jodit.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/izitoast/1.4.0/css/iziToast.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tag-editor/1.0.20/jquery.tag-editor.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jodit/3.2.34/jodit.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/izitoast/1.4.0/js/iziToast.min.js"></script>
</head>
<body>
<div class="admin">
<div class="a-padding"><li class="isni"><a href="#"><i class="fas fa-pen"></i> Write Posts</a></li></div>
<div class="a-padding"><li class="isni"><a href="#"><i class="fas fa-file-alt"></i> View Posts</a></li></div>
<div class="a-padding"><li class="isni"><a href="#"><i class="fas fa-bookmark"></i> Viewers</a></li></div>
<div class="a-padding"><li class="isni"><a href="#"><i class="fas fa-plus"></i> Widget</a></li></div>
</div>
<div class="main-body">
<h1>Start Writing</h1>
<form method="post">
<input type="text" name="title" placeholder="Title" class="form" required>
<div class="form-padding"><input type="text" name="author" placeholder="Author" class="form" required></div>
<div class="form-padding"><input type="text" name="imgurl" placeholder="IMG URL..." class="form"></div>
<div class="form-padding"><input type="text" name="tags" required></div>
<div class="form-padding"><input type="text" name="htags" required></div>
<div class="form-padding"><textarea id="body" name="bodydata" required></textarea></div>
<div class="spacer"><input type="checkbox" name="hpbox"> Make Highlight</div>
<input type="submit" name="post" class="form">
</form>
<!-- This is where the PHP lies -->
</div>

<script>
$(document).ready(function() {
var editor = new Jodit("#body", {
"uploader": {
"insertImageAsBase64URI": true
}
});

});

$('input[name="tags"]').tagEditor({
placeholder: "Meta Tags",
animateDelete: 100
});

$('input[name="htags"]').tagEditor({
placeholder: "Hidden Meta Tags",
animateDelete: 100
});
</script>
</body>
</html>

PHP:

// This is before the HTML
require '../imports/database.php';
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');
// ------ This is the rest of it, placed where the comment is in the HTML section above

if (isset($_POST["post"])) {
if (isset($_POST["hpbox"])) {
$title = $_POST["title"];
$author = $_POST["author"];
$imgurl = $_POST["imgurl"];
$tags = $_POST["tags"];
$htags = $_POST["htags"];
$bd = $_POST["bodydata"];
$date = date("D M d, Y");
$time = date("h:i A");
$p = "true";
$harch_date = date("M Y");

$pinsql = "UPDATE `posts` SET `hp`='false' WHERE `hp`='true'";

if ($con->query($pinsql) === TRUE) {
echo
'
<script type="text/javascript">
iziToast.show({
title: "Success!",
message: "Queried highlight",
backgroundColor: "#37c2dd"
});
</script>
';
} else {
echo "Error updating record: " . $con->error;
}

$stmt = $con->prepare("INSERT INTO `posts` (`title`, `author`, `image`, `bodydata`, `tags`, `htags`, `date`, `time`, `hp`, `arch_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssssssss", $title, $author, $imgurl, $bd, $tags, $htags, $date, $time, $p, $harch_dat);

$stmt->execute();
$stmt->close();


echo
'
<script type="text/javascript">
iziToast.show({
title: "Success!",
message: "Post inserted",
backgroundColor: "#37c2dd"
});
</script>
';
}else {

$title = $_POST["title"];
$author = $_POST["author"];
$imgurl = $_POST["imgurl"];
$tags = $_POST["tags"];
$htags = $_POST["htags"];
$bd = $_POST["bodydata"];
$date = date("D M d, Y");
$time = date("h:i A");
$arch_date = date("M Y");
$p = "false";

$stmt = $con->prepare("INSERT INTO `posts` (`title`, `author`, `image`, `bodydata`, `tags`, `htags`, `date`, `time`, `hp`, `arch_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssssssss", $title, $author, $imgurl, $bd, $tags, $htags, $date, $time, $p, $arch_date);

$stmt->execute();
$stmt->close();
$con->close();

echo
'
<script type="text/javascript">
iziToast.show({
title: "Success!",
message: "Post inserted",
backgroundColor: "#37c2dd"
});
</script>
';
}
}

注意:查看整个文件 https://pastebin.com/xtmSGJRA

导入/database.php 文件:

<?php
$con = new mysqli('localhost', 'root', '', 'WWDB');
?>

最佳答案

我会先尝试找出错误。

我要求 database.php 文件来检查您是否正在检查连接是否成功建立。你不是。您可以在 database.php 文件中使用以下顺序同时启用 mysqli 报告模式:

mysqli_report(MYSQLI_REPORT_STRICT);
try {
$con = new mysqli('localhost', 'root', '', 'WWDB');

if ($con->connect_error) {
die('Connect Error (' . $con->connect_errno . ') ' . $con->connect_error);
}
} catch (Exception $e) {
echo 'ERROR:'.$e->getMessage();
}

在此之后,如果没有显示任何有值(value)的错误,请尝试将执行命令放在类似的 try-catch block 中。我猜你的数据库表结构中可能有一个字段被定义为整数或 bool 值,而你正在向它传递一个字符串值,因此请 try catch 该错误。

编辑:您没有提供更新查询是否有效的信息。如果您只对准备好的语句有问题,而正常的查询正在运行,则您需要尝试不同的方法,那么这真的有效吗?

"UPDATE `posts` SET `hp`='false' WHERE `hp`='true'"

关于php - 当记录没有插入(准备好的语句)时,为什么我没有在 PHP 中收到错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55435357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com