简体   繁体   English

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

[英]adding new article to DB not working

im having a little trouble with my add.php page. 我在我的add.php页面上遇到了一些麻烦。 I have tried many seperate codes but I am not sure why none of them seem to work. 我尝试了许多单独的代码,但不确定为什么它们似乎都不起作用。

None of the codes add to my database and it does not bring any reports back as I have error reporting turned on. 没有代码添加到我的数据库中,并且由于我打开了错误报告,因此它不会带来任何报告。 So I am not sure why. 所以我不确定为什么。

my code for my add.php page is: 我的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');
}


?>

Does any one know why? 有谁知道为什么吗?

thank you. 谢谢。

您的变量都是小写字母,但绑定值时,首字母大写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM