gpt4 book ai didi

php - 向数据库添加新文章不起作用

转载 作者:行者123 更新时间:2023-11-29 13:42:33 25 4
gpt4 key购买 nike

我的 add.php 页面遇到了一些问题。我尝试了许多单独的代码,但我不确定为什么它们似乎都不起作用。

没有任何代码添加到我的数据库中,并且它不会返回任何报告,因为我打开了错误报告。所以我不知道为什么。

我的 add.php 页面的代码是:

    <?php

session_start();

include_once('../include/connection.php');

if (isset($_SESSION['logged_in'])){
if (isset($_POST['title'], $_POST['content'])) {
$title = $_POST['title'];
$content = nl2br($_POST['content']);
$image = $_POST['Image URL'];
$link = $_POST['Link'];
$price = $_POST['Price'];

if (empty($title) or empty($content)) {
$error = 'All Fields Are Required!';
}else{
$query = $sql->prepare('INSERT INTO `xclocouk_mobile`.`mobi` (`promo_title`, `promo_content`, `promo_image`, `promo_link`, `promo_cat`) VALUES (?,?,?,?,?)');
$query->bindValue(1, $Title);
$query->bindValue(2, $Content);
$query->bindValue(3, $Image);
$query->bindValue(4, $Link);
$query->bindValue(5, $Category);

$query->execute();
header('location: index.php');

}

}
?>

<html>
<head>
<title>testing</title>
<link rel="stylesheet" href="../other.css" />
</head>

<body>
<div class="container">
<a href="index.php" id="logo">CMS</a>

<br /><div align="center">


<h1>Add Article</h1>

<?php if (isset($error)) { ?>
<small style="color:#aa0000;"><?php echo $error; ?></small><br /><br />
<?php } ?>


<form name = "myform" action="add.php" method="post" autocomplete="off">


<input type="text" name="Title" placeholder="Title" /><br /><br />
<textarea rows="15" cols="50" name="Content" placeholder="Content"></textarea><br /><br />
<input type="text" name="Image" placeholder="Image URL" /><br /><br />
<input type="text" name="Link" placeholder="Link" /><br /><br />
<input type="text" name="Category" placeholder="Category" /><br /><br />
<input type="submit" name="submit" value="Add Article" />

</form></div>

</div>
</body>
</html>


<?php
}else{
header('location: index.php');
}


?>

有人知道这是为什么吗

谢谢。

最佳答案

您的变量都是小写的,但是在绑定(bind)值时,第一个字母大写。

关于php - 向数据库添加新文章不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17885934/

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