douhao7677 2014-01-02 10:19
浏览 150
已采纳

PHP解析错误:语法错误,意外T_VARIABLE [关闭]

I get this error: PHP Parse error: syntax error, unexpected T_VARIABLE on line 47

The 47th line is:

$queryb = "UPDATE `situation` SET `status`='" . $stats . "', `time`='" . $time . "', `name`='" . $name . "', `notes`='" . $notes . "'";

I just don't get it. Maybe script error or syntax error?

<?php
    function lanjut($c) {
    $submitdata = "success";
    if ($c = "message") {
        $time = $_REQUEST['time'];
        $name = $_REQUEST['name'];
        $body = $_REQUEST['body'];
        $con = mysqli_connect("this,is,already,true");
        $querya = "INSERT INTO `message` (`name`, `time`, `body`) VALUES ('" . $name . "', '" . $time . "', '" . $body . "')";
        mysqli_query($con,$query);
        mysqli_close($con);
    } elseif ($c = "setting") {
        $time = $_REQUEST['time'];
        $name = $_REQUEST['name'];
        $notes = $_REQUEST['notes'];
        $con = mysqli_connect("this,is,already,true");
        $stats = $_REQUEST['status']
        $queryb = "UPDATE `situation` SET `status`='" . $stats . "', `time`='" . $time . "', `name`='" . $name . "', `notes`='" . $notes . "'";
        mysqli_query($con,$query);
        mysqli_close($con);
    };
};
?>
  • 写回答

4条回答 默认 最新

  • dplece1882 2014-01-02 10:32
    关注

    Code without any syntax error will be

    <?php
    function lanjut($c)
    {
        $submitdata = "success";
        if($c = "message") {
            $time = $_REQUEST['time'];
            $name = $_REQUEST['name'];
            $body = $_REQUEST['body'];
            $con = mysqli_connect("this,is,already,true");
            $querya = "INSERT INTO `message` (`name`, `time`, `body`) VALUES ('" . $name . "', '" . $time . "', '" . $body . "')";
            mysqli_query($con, $querya);
            mysqli_close($con);
        } elseif($c = "setting") {
            $time = $_REQUEST['time'];
            $name = $_REQUEST['name'];
            $notes = $_REQUEST['notes'];
            $con = mysqli_connect("this,is,already,true");
            $stats = $_REQUEST['status'];
            $queryb = "UPDATE `situation` SET `status`='" . $stats . "', `time`='" . $time . "', `name`='" . $name . "', `notes`='" . $notes . "'";
            mysqli_query($con, $queryb);
            mysqli_close($con);
        }
    }
    ?>
    

    A better way is to user prepared statements like

    $querya = $con->prepare("INSERT INTO `message` (`name`, `time`, `body`) VALUES (? , ?, ?");
    $querya->bind_param('sss', $name, $time, $body);        
    $querya->execute();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面