This question already has an answer here:
- The 3 different equals 5 answers
- unexpected error message in php form (SQL syntax error) 3 answers
whenever I want to insert data with my form ,everything woks fine except the content field that does not insert anything to db!
Here's my full code:
<?php
if (isset($_POST['submit'])){
$post_title = $_POST['title'];
$post_date = date('d-m-y');
$post_author = $_POST['author'];
$post_keywords = $_POST['keywords'];
$post_content = $_POST['content'];
$post_image = $_FILES['image']['name'];
$image_tmp = $_FILES['image']['tmp_name'];
$post_summary = $_POST['summary'];
if ($post_title=='' || $post_keywords=='' || $post_content='' || $post_author=='' || $post_summary==''){
echo '<script>alert("Some fields are missing")</script>';
}else{
move_uploaded_file($image_tmp,"post_images/$post_image");
$insert_query = "INSERT INTO posts
(post_title, post_date, post_author, post_image, post_keywords, post_content, post_summary)
VALUES ('$post_title', '$post_date', '$post_author', '$post_image', '$post_keywords', '$post_content' , '$post_summary')";
$insert_post = mysqli_query($con,$insert_query);
if ($insert_post){
echo '<h3 style="color:green">Post has been added successfully.</h3>';
}elseif (!$insert_post){
echo mysqli_error($con);
}else{
echo "Somthing goes wrong! Please contact with our support team...";
}
}
}
?>
<form method="POST" action="" enctype="multipart/form-data">
<table width="600" align="center" border="10">
<tr>
<td align="center"><h6>Insert Post Title</h6></td>
<td align="center"><input type="text" name="title"/></td></br>
</tr>
<tr>
<td align="center"><h6>Insert Post Author</h6></td>
<td align="center"><input type="text" name="author"/></td></br>
</tr>
<tr>
<td align="center"><h6>Insert Post Keywords</h6></td>
<td align="center"><input type="text" name="keywords"/></td></br>
</tr>
<tr>
<td align="center"><h6>Insert Post Image</h6></td>
<td align="center"><input type="file" name="image"/></td></br>
</tr>
<tr>
<td align="center"><h6>Insert Post Content</h6></td>
<td align="center"><textarea name="content" cols="10" rows="10"></textarea></td></br>
</tr>
<tr>
<td align="center"><h6>Insert Post Summary</h6></td>
<td align="center"><textarea name="summary" cols="5" rows="5"></textarea></td></br>
</tr>
<tr>
<td align="center"><input type="submit" name="submit" value="Submit"/></td>
</tr>
</table>
</form>
The problem is that the $post_content
variable does not insert anything into post_content
field in my table however the other variables works correctly & also the success message (line 21) appears.
Here's my table structure:
post_id => int(11)
post_title => varchar(100)
post_date => date
post_author => varchar(100)
post_image => image
post_keywords => text
post_content => text
post_summary => text
</div>