dongque8332 2019-03-24 01:48
浏览 62
已采纳

PHP错误:解析错误:语法错误,意外' - >'[重复]

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>
  • 写回答

2条回答 默认 最新

  • dongxi7722 2019-03-24 01:59
    关注
    /*you have forgotten the dollars*/
    mysqli should become
    $mysqli->real_escape_string($_GET['postbox']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?