2016-03-16 2 views
1

Мне интересно, почему мой оператор обновления меняет тип_события всех других записей всякий раз, когда я сохранял отредактированную запись.Оператор обновления не работает должным образом и меняет другие записи

Работала над этим обновлением уже довольно давно, и я просто не могу заставить его работать. Было бы здорово, если бы вы, ребята, могли мне помочь в этом.

Спасибо за помощь! :)

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

+0

Почему вы используете две таблицы здесь 'UPDATE резервирования, место SET venue_type' ?? – Saty

+0

Вы действительно должны подумать о том, чтобы защитить ваши вызовы SQL, как минимум, с помощью любых аргументов с mysql_real_escape_string! http://php.net/mysql_real_escape_string – mtrolle

+0

@mtrolle следить за вашей ссылкой и читать то, что там написано? –

ответ

0

Вы можете попробовать JOIN в запросе

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'" 
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); 
    } 
Смежные вопросы