Update statement not working properly and changes the other records

I'm wondering why my update statement changes the venue_type of all the other records whenever I saved the edited record.

Been working on this update statement for quite sometime now and I just can't get it to work. It would be great if you guys could help me on this.

Thanks for the help! :)

<body>
    <head>
        <script src="js/jquery.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script src="js/smoothscroll.js"></script>
        <script src="js/resetOnClick.js"></script>

        <link href="css/bootstrap.min.css" rel="stylesheet"/>
        <link href="css/styles.css" rel="stylesheet"/>  
        <link href="css/notifbox.css" rel="stylesheet"/>
    </head>

    <center><label class="control-label" style="font-size:30px">Reservation</label></center>
    <center><label class="control-label" style="font-size:15px">Edit Record</label></center>
    <br/>
    <br/>

    <?php
    $id = isset($_GET['id'])? $_GET['id'] : "";




        include('config/config1.php');

        $sel = "SELECT idReservation, venue.venue_type, reservation.reservation_date, reservation.reservation_time
        FROM venue
        INNER JOIN reservation ON reservation.Venue_idVenue = venue.idVenue where idReservation = '$id';";
        $rsvtn = isset($_POST['idReservation']);
        $query = mysqli_query($conn,$sel);

        while($detail = mysqli_fetch_array($query))
        {   
            $rid = $detail['idReservation'];
            $ven = $detail['venue_type'];
            $res_d = $detail['reservation_date'];
            $res_t = $detail['reservation_time'];
    ?>

    <form class="form-horizontal form-label-left" method="post">

        <div class="form-group">
                <!--BACK Button-->
                <a href="Reservation Records.php" class="col-md-6 col-md-offset-3" style="font-size:20px">Back</a>
                <!--BACK Button-->
        </div>
        <!--<input type="hidden" name="submitted" value="true"/>-->
            <div class="item form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12">Venue<span class="required">*</span></label>
                    <div class="col-md-6 col-sm-6 col-xs-12">
                        <input id="venue_type" data-content="<?php echo $ven;?>" class="form-control col-md-7 col-xs-12" name="venue_type" placeholder="Venue" required="required" type="text" value="<?php echo $ven;?>">
                    </div>          
            </div>

            <div class="item form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Reservation Date<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <input id="reservation_date" data-content="<?php echo $res_d;?>" class="form-control col-md-7 col-xs-12" name="reservation_date" placeholder="Reservation Date" required="required" type="date" value="<?php echo $res_d;?>">
                </div>
            </div>

            <div class="item form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Reservation Time<span class="required">*</span></label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <input id="reservation_time" data-content="<?php echo $res_t;?>" class="form-control col-md-7 col-xs-12" name="reservation_time" placeholder="Reservation Time" required="required" type="time" value="<?php echo $res_t;?>">
                </div>
            </div>



            <div class="ln_solid"></div>
            <div class="form-group">
                <div class="col-md-6 col-md-offset-3">
                    <input type="hidden" name="updRsvtn" value="<?php echo $detail['idReservation'];?>">
                    <input type="submit" class="btn btn-primary submits" value="Save Edited" onClick="Reservation Records.php" >
                </div>
            </div>  
            <?php
        } 

    ?>
    <?php
    if(isset($_POST['updRsvtn']))
        {   
            include('config/config1.php');

            $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);
        }
    ?>  
    </form>

    <table class = "notif pos">
      <thead>
        <tr>
          <th><center/><b>*Old Record</b></th>
        </tr>
      </thead>

      <tbody>
        <tr>
          <td><center/><b>Venue: <?php echo $ven;?></td>
        </tr>
        <tr>
          <td><center/><b>Reservation Date: <?php echo $res_d;?></td>
        </tr>
        <tr>
          <td><center/><b>Reservation Time: <?php echo $res_t;?></td>
        </tr>
      </tbody>
    </table>


</body>

Answers


   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);
    }

You could try JOIN in your query

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'"

Need Your Help

PHP Unset is resetting my Session Array

php mysql session unset

I am encountering an issue where i am sending a request to delete a specific product out of a session array. When the results return the session is null and it clearly has more than one value in it...

Separate string using RegExp

php regex

I have a string coming in that has productID's and their quantity separated by comma