2014-02-15 105 views
0

我有添加文章的窗体。我有6件事(标题,日期,作者,keywors,内容,图像)我想要保存到本地主机的数据库中。但是,如果我点击提交按钮在我的数据库中出现只有他们3(标题,日期,图像),但其他什么都没有。PHP,MySQL插入错误

任何想法如何解决它?对于insert_post.php

下面的代码

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<title>APK Market</title> 
<link rel="stylesheet" type="text/css" href="../style/style.css"> 
<link href="../bootstrap/css/bootstrap.css" rel="stylesheet" media="screen"> 
<script src="../bootstrap/js/bootstrap.min.js"></script> 
<script src="../bootstrap/js/bootstrap.js"></script> 
</head> 
<body> 

<?php 
include("../includes/connect.php"); 

if(isset($_POST['submit'])) 
{ 
$post_date = date('y-m-d'); 
$post_title = $_POST['title']; 
$post_author = $_POST['author']; 
$post_keywords = $_POST['keywords']; 
$post_image = $_FILES['image']['name']; 
$image_tmp = $_FILES['image']['tmp_name']; 
$post_content = $_POST['content']; 

if($post_title=="" or $post_author="" or $post_keywords="" or $post_content="") 
{ 
    echo"<script>alert('any field is empty')</script>"; 
    exit(); 
} 
else 
move_uploaded_file($image_tmp,"../uploaded_images/$post_image"); 
$insert_query = "insert into posts    (post_title,post_date,post_author,post_image,post_keywords,post_content) values ('$post_title','$post_date','$post_author','$post_image','$post_keywords','$post_content')"  ; 

    } 
    ?> 
    <form method="post" action="insert_post.php" enctype="multipart/form-data"> 

<div class="new_post"> 
<div class="headtitle">Insert new post</div> 
    <div class="new_title"> 
    <p>New title</p> 
    <input type="text" name="title"> 
    </div> 
<div class="new_author"> 
<p>Author</p> 
<input type="text" name="author"> 
</div> 
<div class="new_keywords"> 
<p>Keywords</p> 
<input type="text" name="keywords"> 
</div> 
<div class="new_image"> 
<p>Image</p> 
<input type="file" name="image"> 
</div> 
<div class="new_content"> 
<textarea name="content" cols="20" rows="8"></textarea> 
</div> 
<div class="submit"> 
<input type="submit" name="submit" value="OK"> 
</div> 
</div> 
</form> 
    <script src="https://code.jquery.com/jquery.js"></script> 
<script src="../bootstrap/js/bootstrap.js"></script> 
</body> 
</html> 

<?php 
if(mysql_query($insert_query)) 
{ 
    echo "<center><h1>Post published seccesfuly!</h1></center>"; 
} 
?> 
+0

哪里是你的查询执行的代码,还提供了表设计 –

+0

也还有后你没有{} –

回答

1
if($post_title=="" or $post_author="" or $post_keywords="" or $post_content="") 


    main error on HERE 
replace it with 

    if($post_title=="" or $post_author=="" or $post_keywords=="" or $post_content=="") 
+0

$ post_author = “” 或者$ post_keywords = “”或$ post_content =“”那个案例新值分配在这个变量中是空的 – wild

+0

ou我是盲人:)谢谢 – psajtik