-2

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!";
    }

}

?>

2 Answers2

0
/*you have forgotten the dollars*/
mysqli should become
$mysqli->real_escape_string($_GET['postbox']);
faso-dev
  • 183
  • 1
  • 3
  • 12
  • When the answer is "you forgot the dollar sign", there is no need to answer. Just leave a comment under the question and flag/vote to close as Off-topic: Typo. This page will be quickly scrubbed from the site (as will any upvote points you receive) because this page is completely useless to researchers. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). – John Conde Mar 24 '19 at 12:13
0

Just Copy and Paste this, You may be a mistake in

mysqli->real_escape_string($_GET['postbox']);

just change it to

$mysqli->real_escape_string($_GET['postbox']);

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!"; } } ?>
  • When the answer is "you forgot the dollar sign", there is no need to answer. Just leave a comment under the question and flag/vote to close as Off-topic: Typo. This page will be quickly scrubbed from the site (as will any upvote points you receive) because this page is completely useless to researchers. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). – John Conde Mar 24 '19 at 12:13