This question already has an answer here:
I am new to PHP. I am trying to create a textbox in html, and take the input via php and store it in my Mysql database.
I can't get past this error.
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR)
I understand the ->
is wrong. But I don't know how to fix it.
Also is there any other errors that you guys see in this code? I appreciate your help.
<form action="user-post.php" method="get">
<input type="post-box" name="postbox" required>
<input type="submit" value="Submit">
</form>
<?php
session_start();
$_SESSION['message'] = '';
$mysqli = new mysqli('localhost:3306', 'root', '1234', 'status-box');
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$postbox = mysqli->real_escape_string($_GET['postbox']);
$sql = "INSERT INTO post (postbox)"
. "VALUES ('$postbox')";
if ($mysqli->query($sql) === true) {
header("location: index.html");
} else {
$_SESSION['message'] = "Post could NOT be added to the database!";
}
}
?>
</div>