2014-10-31 183 views
0

當我從表book更新book_StatusAVAILABLE我沒有成功將reserve_Status更改爲RESERVED。我的腳本有什麼問題?插入數據庫條件

reserve.php

<?php 
     include 'dbconnect.php'; 

     $query1 =" 
        SELECT b.book_Status, r.reserve_Status 

        FROM book b 
        JOIN reservations r 
        ON r.book_Accession = b.book_Accession 
        "; 


     $result1 = mysql_query($query1) or die('SQL error'); 
     $row1 = mysql_fetch_array($result1, MYSQL_ASSOC); 

     if ($row1['book_Status'] == 'Available') 
     { 
      $Reserved = "Reserved"; 

     }    
     $query2 = "INSERT INTO reservations 
         WHERE reserve_Status = '$Reserved' "; 

?> 
+0

請詳細解釋你想做什麼!你不能用'WHERE'子句插入。插入只是插入他們爲什麼會有一個地方。 – CodeBird 2014-10-31 08:41:43

+0

請發表您要使用 – Alepac 2014-10-31 08:42:59

+0

提示表的完整結構:你應該做一個'UPDATE'查詢,而不是插入 – 2014-10-31 08:43:56

回答

0

你需要一個update query。並移動查詢到您的if聲明

if ($row1['book_Status'] == 'Available') 
     { 
      $Reserved = "Reserved"; 
$query2 = "UPDATE reservations SET reserve_status = 'reserved' WHERE book_Status='Available'"; 

     }  
+0

感謝您的編碼..但reserve_Status和book_Status是不同的表.. – 2014-10-31 09:01:22

0

的問題是,你改變了變量$Reserved的價值,但你並沒有查詢到執行更新數據庫。