2014-02-15 4 views
0

У меня есть форма для добавления статей. У меня есть 6 вещей (название, дата, автор, ключевые слова, контент, изображение), которые я хочу сохранить в моей базе данных в localhost. Но если я нажму кнопку отправки в моей базе данных, появятся только 3 из них (название, дата, изображение), но ничего другого.PHP, MySQL insert error

Любые идеи, как их решить?

Вот код 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 i am blind :) спасибо – psajtik