2013-07-26 33 views
0

即时通讯我的add.php页面有点麻烦。我已经尝试了许多单独的代码,但我不确定为什么他们似乎没有工作。将新文章添加到DB不工作

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

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


?> 

任何一个人知道为什么吗?

谢谢。

+0

它发布到add.php,所以这将是一个很好的开始寻找的地方。 – 2013-07-26 16:03:32

+0

这是我的add.php页面 – kevstarlive

+0

我认为add.php的代码是HTML标签上方的PHP代码块? – 2013-07-26 16:06:14

回答

1

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

+0

好吧我已经改变了他们,但突然间我得到这个错误信息:警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 头已发送(输出开始在/add.php:1 )位于第3行的/add.php中 – kevstarlive

+0

在session_start()之前,不能将任何内容发送到浏览器。尝试取出<?之间的界限和session_start()以及<?之前的空格。 –