PHP空字段错误

时间:2017-02-24 22:42:41

标签: php html

我正在创建一个网站,我在网站上有一个文本框。当用户点击发布时,网站的一部分会检查该字段是否为空。当我点击提交是否我发布了什么,我得到了else语句。有人能帮助我吗?

home.php:

<form action="poststatus.php" method="post">
<button id="bt6" type="submit" name="status">Post status to your  timeline</button>
<b><div contenteditable="true" placeholder="Post status" id="content"></div></b>

</form>

poststatus.php:

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

include("connect.php");
include("auth_login.php"); 

GLOBAL $username;
GLOBAL $post;
GLOBAL $date;


if(isset($_POST['status'])) {

if (empty($_POST["content"])) {
    echo"You didn't enter anything . <a href= home.php>Try again</a>";
    }

$sql = "INSERT INTO posts (username, post, d-m-Y) VALUES ('" . $username . "', '" . $post . "', '" . $date . "' )";

if(mysqli_query($conn, $sql)){                                  

echo"Your post was added."; 
} else{
    echo"<br>error posting . <a href= home.php>Try again</a> ";
} 
} 
?>

1 个答案:

答案 0 :(得分:0)

您需要提供<div>属性name="content"

<div contenteditable="true" placeholder="Post status" name="content" id="content"></div>