私はPHPでソーシャルウェブサイトを作成しています。ユーザーは自分のタイムラインにステータスを投稿するオプションを持っていますが、タイムラインに投稿しようとすると、Post added to your timeline.
echoステートメントが表示されますが、データベースのオンラインに移動すると、ユーザー名列に記入され、誰か助けてくれますか?MYSQL PHPカラムが空
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>
poststatus.php:あなたはとてもあなたのコードはそのようになっているはずです、$body
変数は、それが価値だを取得する必要がありから定義していない
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);
}
}
}
が耀輝確認耀輝$のユーザー名と$ bodyの適切な値を持っているしてみてください。 ..挿入する前にvar:dump($ username)を試してください。 – scaisEdge
空の値を挿入しています。この行が変数を何に設定したと思いましたか?: '$ body = '';'このコードは** SQLインジェクション**に広く開かれていて、ユーザーはあなたのサーバー上で任意のコードを実行できます。 – David
それは私にこれを示していると私はそれが意味するものがわからない 'C:\ wamp \ www \ testwebsite \ poststatus.php:14:string 'username264'(長さ= 11) ' – mkd