我目前正在创建一个cms,除了add.php页面外,其他都很好。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 = $pdo->prepare('INSERT INTO `apps`(`app_id`, `app_title`, `app_content`, `app_img`, `app_link`, `app_price`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6])');
$query->execute(array(
':title' => $title,
':content' => $content,
':image' => $image,
':link' => $link,
':price' => $price
));
$query->execute();
}if($result){
echo("<br>Input data is successful");
} else{
echo("<br>Input data failed");
}
}
?>
<html>
<head>
<title>testing</title>
<link rel="stylesheet" href="../style.css" />
</head>
<body>
<div class="container">
<a href="index.php" id="logo">CMS</a>
<br />
<h4>Add Article</h4>
<?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" placeholder="Content" name="content"></textarea><br /><br />
<input type="text" name="Image URL" placeholder="Image URL" /><br /><br />
<input type="text" name="Link" placeholder="Link" /><br /><br />
<input type="text" name="Price" placeholder="Price" /><br /><br />
<input type="submit" name="submit" value="Add Article" />
</form>
</div>
</body>
</html>
<?php
}else{
header('location: index.php');
}
error_reporting(E_ALL);
?>
我的问题是。我的代码在我的错误日志中没有显示任何错误,并且人们告诉我它没问题。但它不会添加到数据库中。有没有一种方法可以分解每一个代码并找出发生了什么?
或者有没有办法显示错误可能是什么?我的错误报告已通过E_ALL |打开E_STRICT仍然没有。
请帮忙
谢谢。
嗨。我的应用程序ID是一个自动增量,我该如何添加? – kevstarlive
嗨。所以你的'app_id'是你的主键还是不是?如果你有你自己的机制来生成你的'app_id',只需将'app_id'字段及其占位符添加到prepare语句中,并在使用'execute'方法时插入生成的id。否则,您应该将此字段格式化为自动增量字段。 –
我的app_id不是主键。即时通讯不知道如何将此字段格式化为自动增量字段。请你能告诉我如何?谢谢。 – kevstarlive