数据库不存储更新的值

时间:2019-12-21 12:08:39

标签: php mysql

大家好,这是我对getbooking.php的编码,它还与updatebooking.php相关。

但是,当我尝试更新我的预订时。它说预订已更新,但是新值未存储在数据库中。

我的主要问题是,当我尝试更新时,数据库中的值不会更改。

我迷失了编码的问题。我仍在学习。请指出我在编码中可能没有意识到的任何错误。

这是我的dbh.php

<?php
$db_host="localhost";
$db_username="";
$db_pass="";
$db_name="";
$conn=mysqli_connect($db_host,$db_username,$db_pass,$db_name) or die
("could not connect to MySQL");
?>

这是我的getbooking.php

<?php
include 'dbh.php';

if(isset($_POST['submit-search'])){
$search=mysqli_real_escape_string($conn,$_POST['search']);
$sql="SELECT * FROM BOOKING WHERE APPLICANT_WORKERSNUM_IC_MATRICNUM='$search';";
$result=mysqli_query($conn,$sql);
$resultCheck=mysqli_num_rows($result);

if($resultCheck>0){
        $row=mysqli_fetch_assoc($result);
        $appid=$row['APPLICANT_WORKERSNUM_IC_MATRICNUM'];
        $btype = $row['BUS_TYPE'];
        $pnum = $row['NUM_OF_PASSENGERS'];
        $dreq = $row['DATE_REQUIRED'];
        $treq = $row['TIME_REQUIRED'];
        $dtn = $row['DESTINATION'];
        $wta = $row['WAITING_AREA'];

        echo "<left>";
        echo "<fieldset>";
        echo "<h2> Booking Details </h2>";
        echo "<form action='updatebooking.php' method='POST'>";
        echo "Applicant's Worker Number/IC/Matric Number : {$appid} </br>";
        echo "<input type='hidden' value='$appid' name='appid'>";
        echo "Bus Type : {$btype}</br>
            Number Of Passengers : <input type='text' name='pnum' value='$pnum'></br>
            Date Required : <input type='date' name='dreq' value='$dreq'></br>
            Time Required : <input type='time' name='treq' value='$treq'></br>
            Destination : <input type='text' name='dtn' value='$dtn'></br>
            Waiting Area : <input type='text' name='wta' value='$wta'>";
        echo "<button type ='submit' name = 'submit-update'>Update Booking</button>";
        echo "<button type ='submit' name = 'submit-delete'>Delete Booking</button>";
        echo "</form>";
        echo "</fieldset>";
        echo "</left>";
    }
 else{
    echo "There are no results matching your search";
  }
}
?>

这是我的updatebooking.php

<?php
include 'dbh.php';

if(isset ($_POST ['submit-update'])){
$pnum =mysqli_real_escape_string($conn,$_POST['pnum']);
$dreq =mysqli_real_escape_string($conn,$_POST['dreq']);
$treq= mysqli_real_escape_string($conn,$_POST['treq']);
$dtn =mysqli_real_escape_string($conn,$_POST['dtn']);
$wta =mysqli_real_escape_string($conn,$_POST['wta']);

$sql ="UPDATE `booking` SET NUM_OF_PASSENGERS='$pnum',DATE_REQUIRED='$dreq',
TIME_REQUIRED='$treq',DESTINATION='$dtn',WAITING_AREA='$wta' 
WHERE APPLICANT_WORKERSNUM_IC_MATRICNUM='$appid'";
$result = mysqli_query($conn, $sql);
if ($result){
    echo "<script type='text/javascript'>alert ('Record updated successfully');
    location = '../index.php?update=failed'</script>";
}
else{
    echo "<script type='text/javascript'>alert ('Error updating record');
    location = '../index.php?update=failed'</script>";
}
}

else{
if(isset($_POST['submit-delete'])){
    $appid = mysqli_real_escape_string($conn, $_POST['appid']);
    $sql = "DELETE FROM 'BOOKING' WHERE APPLICANT_WORKERSNUM_IC_MATRICNUM='$appid'";
    $result = mysqli_query($conn, $sql);
    if ($result){
        echo "<script type = 'text/javascript'>alert('Record deleted successfully');
    location='../index.php?delete=success'</script>";
    }
    else{
        echo "script type='text/javascript'>alert('Error deleting record');
    location = '../index.php?delete=failed'</script>";
    }
  }
  }
  ?>

0 个答案:

没有答案