如何解决这个错误PHP Parse错误:语法错误,意外';'?

时间:2017-08-10 09:31:37

标签: php

我认为插入查询应以分号结尾,因为类似的代码适用于另一个表单。但它显示了这个错误:

PHP Parse error: syntax error, unexpected ';'

这是我的PHP脚本,用于从表单中将数据插入数据库。

if((!empty($name) && !empty($location) && !empty($fulladdress) && !empty($ownername) && !empty($ownercontact) && !empty(category) && 
                    ($invalidphflag==true) && ($phoneflag==true) && !empty($size) && !empty($price) )
        {
                $insertquery= "INSERT INTO properties (name, location, address, owner_name, owner_no, size, price, category) 
                VALUES ('$name', '$location', '$fulladdress', '$ownername', '$ownercontact', '$size', '$price', '$category')";

            $query = mysqli_query($db, $insertquery);

            if($query)
            {
             $success= "Details submitted successfully.";
            }   



    }

4 个答案:

答案 0 :(得分:1)

if(!empty($name) && !empty($location) && !empty($fulladdress) && !empty($ownername) && !empty($ownercontact) && !empty($category) &&
    ($invalidphflag==true) && ($phoneflag==true) && !empty($size) && !empty($price) ) {
    $insertquery= "INSERT INTO properties (name, location, address, owner_name, owner_no, size, price, category) 
                VALUES ('$name', '$location', '$fulladdress', '$ownername', '$ownercontact', '$size', '$price', '$category')";

    $query = mysqli_query($db, $insertquery);

    if($query)
    {
        $success= "Details submitted successfully.";
    }
}

答案 1 :(得分:1)

if语句中有一个未关闭的括号。

所以你的if语句应该是这样的:

 if ((!empty($name) && !empty($location) && !empty($fulladdress) && !empty($ownername) && !empty($ownercontact) && !empty(category) && 
        ($invalidphflag==true) && ($phoneflag==true) && !empty($size) && !empty($price) 
    ))

导致:

 if ((!empty($name) && !empty($location) && !empty($fulladdress) && !empty($ownername) && !empty($ownercontact) && !empty(category) && 
    ($invalidphflag==true) && ($phoneflag==true) && !empty($size) && !empty($price) 
))
{
    $insertquery= "INSERT INTO properties (name, location, address, owner_name, owner_no, size, price, category) 
        VALUES ('$name', '$location', '$fulladdress', '$ownername', '$ownercontact', '$size', '$price', '$category')";

    $query = mysqli_query($db, $insertquery);

    if ($query)
    {
        $success= "Details submitted successfully.";
    }   
}

答案 2 :(得分:1)

if((!empty($name)
    && !empty($location)
    && !empty($fulladdress)
    && !empty($ownername)
    && !empty($ownercontact)
    && !empty($category)
   )
&&
   ($invalidphflag == true
   && $phoneflag == true
   && !empty($size)
   && !empty($price)
   )){
        $insertquery= "INSERT INTO properties (name, location, address, owner_name, owner_no, size, price, category) 
                VALUES ('$name', '$location', '$fulladdress', '$ownername', '$ownercontact', '$size', '$price', '$category')";
        $query = mysqli_query($db, $insertquery);
        if($query)
        {
           $success= "Details submitted successfully.";
        }   
   }

您在条件的第一部分$错过了!empty(category)个签名

答案 3 :(得分:0)

if((!empty($name) && !empty($location) && !empty($fulladdress) && !empty($ownername) && !empty($ownercontact) && !empty(category) && ($invalidphflag==true) && ($phoneflag==true) && !empty($size) && !empty($price) )

还有一个开场括号(而不是关闭)