2017-08-10 132 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部分

相關問題