psajtik
psajtik

Reputation: 45

PHP, MySQL insert error

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>";
}
 ?>

Upvotes: 0

Views: 95

Answers (1)

wild
wild

Reputation: 340

    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=="")

Upvotes: 1

Related Questions