2016-11-11 169 views
0

我想從1個表格更新兩個表,但它不斷給我這個錯誤更新MySQL表 - PHP

警告:mysqli_fetch_assoc()預計參數1被mysqli_result,在給定的boolean C:\ XAMPP \ htdocs中\ ethicaOak \上線27

公共\ prop.php我敢肯定,這不是做只是不知道爲什麼它給我的錯誤會有些幫助一個有問題?

if (isset($_POST['submit'])){ 
    $prop_title = $_POST['prop_title']; 
    $prop_summary = $_POST['summary']; 
    $prop_details = $_POST['prop_details']; 
    $prop_details = $_POST['category']; 
    $price = $_POST['price']; 
    $price_before = $_POST['price_before']; 
    $from = $_POST['from']; 
    $currency = $_POST['currency']; 
    $payment = $_POST['payments']; 

    $query = "UPDATE properties SET "; 
    $query .= "prop_title = '{$prop_title}' "; 
    $query .= "prop_summary = '{$prop_summary}' "; 
    $query .= "prop_details = '{$prop_details}' "; 
    $query .= "category = '{$category}' "; 
    $query .= "LIMIT 1 "; 
    $query .= "WHERE property_id = '{$manage_prop_id}'"; 
     //{$manage_prop_id} 
    $result = mysqli_query($connection, $query); 

    $rows = mysqli_fetch_assoc($result); 

    $query = "UPDATE prop_price SET "; 
    $query .= "price = '{$price}' "; 
    $query .= "price_before = '{$price_before}' "; 
    $query .= "currency = '{$currency}' "; 
    $query .= "per_payment = '{$per_payment}' "; 
    $query .= "from_payment = '{$from_payment}' "; 
    $query .= "WHERE price_id = '{$manage_prop_id}'"; 
     //{$manage_prop_id} 
    $result2 = mysqli_query($connection, $query); 

    $rows2 = mysqli_fetch_assoc($result2); 
     }else{ 
    ?> 

    <?php 

     $manage_prop_id = null; 

     if (isset($_GET['manage'])){ 
     $manage_prop_id = $_GET['manage']; 
     } 
     else 
     { 
     $manage_prop_id = null; 
     } 


    ?> 

     <input type="text" class="form-control" id="prop_title" name= "prop_title"    
          placeholder="Property Title" value ="<?php echo  $rows['prop_title'];?>" >  
     <input type="text" class="form-control" name="summary" id="summary" placeholder="Property Summary" value = "<?php echo $rows['prop_summary'];?>"> 

     <input type="text" class="form-control" id="price" name= "price" placeholder="Price of Property" value = "<?php echo $rows2['price'];?>"> 
+0

你的代碼可以廣泛應用於[SQL注入攻擊](https://en.wikipedia.org/wiki/SQL_injection)。你應該閱讀[參數化查詢](https://secure.php.net/manual/en/mysqli.prepare.php)。 – Chris

+4

'mysqli_query()'在成功更新時返回'TRUE'。它只返回'SELECT,SHOW,DESCRIBE或EXPLAIN'查詢的數據。 http://php.net/manual/en/mysqli.query.php 爲什麼在更新後嘗試讀取行? – Jaime

回答

0

您要定義的類別爲prop_details

$prop_details = $_POST['category']; 

,並試圖使用不存在

$query .= "category = '{$category}' "; 

這樣一個$類變量,你的查詢可以失敗,返回false。

編輯:正如@Jaime所說,更新查詢只返回true或false,沒有辦法(也沒有理由)提取更新,因爲它不返回數據。