I am creating a social website with PHP . The user has the option to post a status to their timeline .But when I try to post to my timeline I get the Post added to your timeline.
echo statement but when I go to my database online the username column is filled out and the body is empty . Can someone help me ?
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:
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);
}
}
}