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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里