0

I have form for adding articles. I have 6 things (title,date,author,keywors,content,image) what I want to save to my database in localhost. But if I click on submit button in my database appear only 3 of them (title, date, image) but other nothing.

Any ideas how to solve it?

Here code for 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>";
}
 ?>
2
  • where is your query execution code,also provide the table design Commented Feb 15, 2014 at 11:34
  • also after else you have no {} Commented Feb 15, 2014 at 11:39

1 Answer 1

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=="")
Sign up to request clarification or add additional context in comments.

1 Comment

$post_author="" or $post_keywords="" or $post_content="" it that case new value assign in this varible which is blank

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.