我目前正在創建我的網站,已經開始在那裏我將內容添加到我的數據庫表中未添加到數據庫
我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 = $pdo->prepare('INSERT INTO apps (app_title, app_content, app_img, app_link, app_price) VALUES(?, ?, ?, ?, ?)');
$query->bindValue(1, $title);
$query->bindValue(2, $content);
$query->bindValue(3, $image);
$query->bindValue(4, $link);
$query->bindValue(5, $price);
$query->execute();
header('location: index.php');
}
}
?>
<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 action="add.php" method="post" autocomplete="off">
<input type="text" value="" name="title" placeholder="Title" /><br /><br />
<textarea rows="15" cols="50" value="" placeholder="Content" name="content"></textarea><br /><br />
<input type="text" value="" name="Image URL" placeholder="Image URL" /><br /><br />
<input type="text" value="" name="Link" placeholder="Link" /><br /><br />
<input type="text" value="" name="Price" placeholder="Price" /><br /><br />
<input type="submit" name="submit" value="Add Article" />
</form>
</div>
</body>
</html>
<?php
}else{
header('location: index.php');
}
?>
它加載確定並在顯示器上顯示工作文件,但它不會將信息添加到我的數據庫中,稱爲apps。
請問有人能告訴我爲什麼嗎?
謝謝。
你在哪裏創建'$ pdo'?你有錯誤報告打開嗎? –
嗨。我唯一的錯誤日誌是在頁面沒有加載時創建的cPanel。在頁面加載時,在此錯誤日誌中不會顯示任何內容。有沒有另一種方法來獲取所有錯誤? – kevstarlive
上面的文件被稱爲add.php是,如上所述。 – kevstarlive