Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MYSQL PHP列为空_Php_Html_Mysql_Mysqli - Fatal编程技术网

MYSQL PHP列为空

MYSQL PHP列为空,php,html,mysql,mysqli,Php,Html,Mysql,Mysqli,我正在用PHP创建一个社交网站。用户可以选择将状态发布到他们的时间线上。但是当我尝试发布到我的时间线上时,我会将发布添加到您的时间线上。echo语句,但是当我联机访问我的数据库时,用户名列已填写,正文为空。有人能帮我吗 profile.php: <form action="poststatus.php" method="post"> <textarea rows="3" cols="25" name="status" id="status"> </textarea&

我正在用PHP创建一个社交网站。用户可以选择将状态发布到他们的时间线上。但是当我尝试发布到我的时间线上时,我会将
发布添加到您的时间线上。
echo语句,但是当我联机访问我的数据库时,用户名列已填写,正文为空。有人能帮我吗

profile.php:

<form action="poststatus.php" method="post">
<textarea rows="3" cols="25" name="status" id="status">
</textarea>
<button id="bt4" type="submit" name="bts">Post status</button>
</form>
<form action="poststatus.php" method="post">
<textarea rows="3" cols="25" name="status" id="status">
</textarea>
<button id="bt4" type="submit" name="bts">Post status</button>
</form>

职位状态
poststatus.php:

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

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

// just define at the top of the script index.php
$username = ''; 
 $username = $_SESSION['username'];

$body = ''; 

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

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

   $sql = "INSERT INTO posts (username, body ) VALUES ('" . $username . "', '" . $body . "')";

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

echo"<a href= home.php>Post added to your timeline.</a>"; 
} else{
    echo "<br>error posting . <br> <a href= profile.php>Try again</a> " . 
mysqli_error($conn);
} 
 } 
}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

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

// just define at the top of the script index.php
$username = ''; 
 $username = $_SESSION['username'];

$body = ''; 

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

if (empty($_POST["status"])) {
    echo"You didn't enter anything . <a href= profile.php>Try again</a>";
    } else {
   $body = $_POST["status"];
   $sql = "INSERT INTO posts (username, body ) VALUES ('" . $username . "', '" . $body . "')";

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

echo"<a href= home.php>Post added to your timeline.</a>"; 
} else{
    echo "<br>error posting . <br> <a href= profile.php>Try again</a> " . 
mysqli_error($conn);
} 
 } 
}
ini\u集('display\u errors',1);
ini设置(“显示启动错误”,1);
错误报告(E_全部);
包括(“connect.php”);
包括(“auth_login.php”);
//只需在脚本index.php的顶部定义
$username='';
$username=$\会话['username'];
$body='';
如果(isset($_POST['bts'])){
如果(空($_POST[“status”])){
echo“您没有输入任何内容。”;
}否则{
$sql=“插入帖子(用户名,正文)值(““$username.”,“$body.”);
if(mysqli_查询($conn,$sql)){
回声“;
}否则{
回显“
错误发布。
”。 mysqli_错误($conn); } } }
您尚未定义从何处
$body
变量应获取其值,因此您的代码应如下所示:

profile.php:

<form action="poststatus.php" method="post">
<textarea rows="3" cols="25" name="status" id="status">
</textarea>
<button id="bt4" type="submit" name="bts">Post status</button>
</form>
<form action="poststatus.php" method="post">
<textarea rows="3" cols="25" name="status" id="status">
</textarea>
<button id="bt4" type="submit" name="bts">Post status</button>
</form>

职位状态
poststatus.php:

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

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

// just define at the top of the script index.php
$username = ''; 
 $username = $_SESSION['username'];

$body = ''; 

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

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

   $sql = "INSERT INTO posts (username, body ) VALUES ('" . $username . "', '" . $body . "')";

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

echo"<a href= home.php>Post added to your timeline.</a>"; 
} else{
    echo "<br>error posting . <br> <a href= profile.php>Try again</a> " . 
mysqli_error($conn);
} 
 } 
}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

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

// just define at the top of the script index.php
$username = ''; 
 $username = $_SESSION['username'];

$body = ''; 

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

if (empty($_POST["status"])) {
    echo"You didn't enter anything . <a href= profile.php>Try again</a>";
    } else {
   $body = $_POST["status"];
   $sql = "INSERT INTO posts (username, body ) VALUES ('" . $username . "', '" . $body . "')";

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

echo"<a href= home.php>Post added to your timeline.</a>"; 
} else{
    echo "<br>error posting . <br> <a href= profile.php>Try again</a> " . 
mysqli_error($conn);
} 
 } 
}
ini\u集('display\u errors',1);
ini设置(“显示启动错误”,1);
错误报告(E_全部);
包括(“connect.php”);
包括(“auth_login.php”);
//只需在脚本index.php的顶部定义
$username='';
$username=$\会话['username'];
$body='';
如果(isset($_POST['bts'])){
如果(空($_POST[“status”])){
echo“您没有输入任何内容。”;
}否则{
$body=$_POST[“status”];
$sql=“插入帖子(用户名,正文)值(““$username.”,“$body.”);
if(mysqli_查询($conn,$sql)){
回声“;
}否则{
回显“
错误发布。
”。 mysqli_错误($conn); } } }

另外,您不应该使用clear myslq_query,因为这对MySQL注入是危险的,请尝试使用PDO

yiu是否确定yiu在$username和$body中有正确的值。。。请在插入之前尝试var:dump($username)。因为插入的是空值。您认为这一行将变量设置为什么?:
$body=''
还要注意,这段代码对SQL注入非常开放,您允许用户在您的服务器上执行任意代码。它向我展示了这一点,我不知道这是什么意思
C:\wamp\www\testwebsite\poststatus.php:14:string'username264'(length=11)
@davidi做了这件事
$body=''$body=$\u会话['body']但同样的事情是happening@mkd:那么会话值似乎没有设置为任何值。你把它放在哪里?为什么要插入会话值而不是表单中发布的值?注意:这对SQL注入仍然是开放的,不应该在任何实时系统中使用。现在我得到的是else语句
您没有输入任何内容。再试一次
@David是的,当然,我在第一版中提到过。他更应该使用PDO或至少
mysqli\u real\u escape\u string
@mkd您还应该更改HTML部分中字段的名称。感谢它能工作,我接受了答案。我应该使用什么
mysqli\u real\u escape\u string
?像什么弦?