2017-08-10 100 views
-2

我认为插入查询应该以分号结尾,因为类似的代码正在为另一个表单工作。但它显示了这个错误:如何解决这个错误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."; 
      } 



    } 
+1

你在第一次IF声明结束时错过了括号。没有必要为所有这些答案,这是一个简单的错字。 – MinistryofChaps

回答

0

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

多了一个开括号(比关闭)

+0

或者少一个,只要它没有意义就有2个:) – Vladislav

+0

如果没有'$'一起工作将会如何工作!empty(category)? –

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

您的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."; 
    } 
} 
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部分

相关问题