【问题标题】:adding new article to DB not working向数据库添加新文章不起作用
【发布时间】:2013-07-26 15:58:54
【问题描述】:

我的 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');
}


?>

有人知道为什么吗?

谢谢。

【问题讨论】:

  • 它正在发布到 add.php,所以这是一个开始寻找的好地方。
  • 那是我的 add.php 页面
  • 我认为 add.php 的代码是 HTML 标签上方的 PHP 块?
  • 上面的整个代码就是我的 add.php 页面上的代码
  • 当您将自己的代码、数据库调用和 HTML 混为一谈时,各种事情都可能而且将会出现可怕的错误。您是否有任何理由不使用 popular PHP framework 来使其更加标准化和可测试?

标签: php mysql content-management-system admin


【解决方案1】:

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

【讨论】:

  • 好的,我已经更改了它们,但突然间我收到了以下错误消息:警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送(输出已启动在 /add.php:1) 在 /add.php 的第 3 行
  • 在 session_start() 之前不能向浏览器发送任何内容。尝试去掉 之前的任何空格
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-31
  • 1970-01-01
相关资源
最近更新 更多