PHP Parse错误:语法错误,意外T_VARIABLE

时间:2014-01-02 10:19:05

标签: php mysql

我收到此错误:PHP Parse error: syntax error, unexpected T_VARIABLE on line 47

第47行是:

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

我只是不明白。可能是脚本错误或语法错误?

<?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 个答案:

答案 0 :(得分:4)

第46行应以分号结尾:

$stats = $_REQUEST['status'] <---

顺便说一句,你应该使用prepared statements

答案 1 :(得分:3)

没有任何语法错误的代码将是

<?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);
    }
}
?>

更好的方法是使用准备好的语句,如

$querya = $con->prepare("INSERT INTO `message` (`name`, `time`, `body`) VALUES (? , ?, ?");
$querya->bind_param('sss', $name, $time, $body);        
$querya->execute();

答案 2 :(得分:2)

在这里添加分号:

$stats = $_REQUEST['status'];

答案 3 :(得分:0)

将此更改为mysqli_query($con,$querya);,即您没有$query变量。在第一个 if 语句中,同样在 mysqli_query($con,$queryb); 语句中执行此elseif

并在$stats = $_REQUEST['status']; //<------处添加分号MillaresRoomoonwave99