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条)

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办