更新语句无法正常工作并更改其他记录

时间:2016-03-16 11:57:36

标签: php html mysqli

我想知道为什么每当我保存编辑过的记录时,我的更新语句都会更改所有其他记录的venue_type。

现在正在处理这个更新声明已经有一段时间了,我无法让它工作。如果你们能帮助我,那就太好了。

感谢您的帮助! :)

<div id="defaultCountdown" class="hasCountdown">
    <span data-days></span>,
    <span data-hours></span>,
    <span data-minutes></span>,
    <span data-seconds></span>
</div>

2 个答案:

答案 0 :(得分:2)

   if its not working that means your their is not value in 
   $_GET['id']. then $id is having blank value that's why your query 
   update for all rows. 

if(isset($_POST['updRsvtn']))
    {   
        $id = isset($_GET['id'])? $_GET['id'] : "";
        $ven = $_POST['venue_type'];
        $res_d = $_POST['reservation_date'];
        $res_t = $_POST['reservation_time'];
       if(!mysqli_query($conn,"UPDATE reservation, venue SET 
        venue_type = '$ven', reservation_date = '$res_d', 
        reservation_time = '$res_t' WHERE idReservation = '$id'"))
        {
            echo "Not Queried: Wrong variables !";
        }   
        else
        {
            header("Location: Reservation Records.php");

        }
        mysqli_close($conn);
    }

答案 1 :(得分:0)

您可以在查询中尝试加入

UPDATE reservation t1 
JOIN venue t2 ON (t1.Venue_idVenue = t2.idVenue) 
SET t1.reservation_date = '$res_d', 
    t1.reservation_time = '$rest_t', 
    t2.venue_type       = '$ven'
WHERE t1.idReservation  = '$id'"