从表单更新mysql表 - php

时间:2016-11-11 17:43:26

标签: php mysql

我正在尝试从1个表单更新两个表,但它一直在给我这个错误

  

警告:mysqli_fetch_assoc()要求参数1为mysqli_result,第27行的C:\ xampp \ htdocs \ ethicaOak \ public \ 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'];?>">

1 个答案:

答案 0 :(得分:0)

您将类别定义为prop_details

$prop_details = $_POST['category']; 

并尝试使用不存在的$ category变量

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

这样,您的查询可能会失败并返回false。

编辑:正如@Jaime所说,更新查询只返回true或false,没有办法(也没有理由)获取更新,因为它不会返回数据。