向某行提交操作时,其他行受到影响,或者最后插入的行正在执行该操作,而不是所选行。
截图:https://imgur.com/gallery/rnVJjhP
public static function update_booking_status($room_no){
Global $pdo;
$sql="update rooms set booking='Success' where room_no=:room_no";
$rslt=$pdo->prepare($sql);
$rslt->bindParam(':room_no',$room_no,PDO::PARAM_STR);
$rslt->execute();
}
public static function cancel_booking_status($room_no){
Global $pdo;
$sql="UPDATE rooms SET booking='No' WHERE room_no=:room_no";
$rslt=$pdo->prepare($sql);
$rslt->bindParam(':room_no',$room_no,PDO::PARAM_STR);
$rslt->execute();
}
public static function pending_booking_status($room_no){
Global $pdo;
$sql="UPDATE rooms SET booking='Pending' WHERE room_no=:room_no";
$rslt=$pdo->prepare($sql);
$rslt->bindParam(':room_no',$room_no,PDO::PARAM_STR);
$rslt->execute();
}
public static function delete_from_booking_status($room_no){
//echo $room_no;
Global $pdo;
$sql="DELETE from booking WHERE room_no=:room_no";
$rslt=$pdo->prepare($sql);
$rslt->bindParam(':room_no',$room_no,PDO::PARAM_STR);
$rslt->execute();
}
public static function getid($number){
return $number;
}
public static function date_compare_booking_update(){
Global $pdo;
$sql="UPDATE rooms,booking SET rooms.booking='No' where booking.tdate < CURDATE() and booking.room_no=rooms.room_no"; //Update booking status
$st=$pdo->prepare($sql);
$st->execute();
$qry="SELECT rooms.room_no from rooms,booking where booking.tdate < CURDATE() and booking.room_no=rooms.room_no";//Catch the room_no
$stmt = $pdo->prepare($qry);
$stmt->execute();
while($obj = $stmt->fetchObject()){
$room_no = $obj->room_no;
operations::delete_from_booking_status($room_no);
}
}
public static function show_booking(){
Global $pdo;
Global $pending_booking_statuso;
operations::date_compare_booking_update();
$qry="SELECT rooms.price, booking.room_no,booking.fdate,booking.tdate,booking.name,booking.phone,booking.code,booking.address,rooms.booking,rooms.assigned_to from booking left join rooms ON booking.room_no=rooms.room_no";
//$qry = "SELECT * FROM booking ";
$stmt = $pdo->prepare($qry);
$stmt->execute();
while($obj = $stmt->fetchObject()){
$price=$obj->price;
$fdate = $obj->fdate;
$tdate = $obj->tdate;
$name = $obj->name;
$phone=$obj->phone;
$code = $obj->code;
$address = $obj->address;
$room_no = $obj->room_no;
$booking = $obj->booking;
$assigned_to=$obj->assigned_to;
echo "
<tr>
<td>$room_no</td>
<td>$fdate</td>
<td>$tdate</td>
<td>$name</td>
<td>$phone</td>
<td>$code</td>
<td>$address</td>
<td>$booking</td>
<td>$assigned_to</td>
<td>
<form action='booking.php' method='post'>
<select name='todo'>
<option value=''>----------</option>
<option value='pending'>Pending</option>
<option value='cancelled'>Cancelled</option>
<option value='success'>Success</option>
</select>
<span><input type='submit' name='submit' value='Submit' class='btn btn-primary'></span>
</form>
</td>
</tr>
";
if(isset($_POST['submit'])){
if($_POST['todo']=='pending'){
echo'pending';
echo $room_no;
operations::pending_booking_status($room_no);
//header("Location:booking.php");
}
else if($_POST['todo']=='cancelled'){
echo'cancelled';
echo $room_no;
operations::cancel_booking_status($room_no);
operations::delete_from_booking_status($room_no);
//header("Location:booking.php");
}
else if($_POST['todo']=='success'){
echo 'Success';
echo $room_no;
operations::update_booking_status($room_no);
operations::insert_room_booking_history($room_no,$fdate,$tdate,$name,$phone,$code,$address,$price);
//header("Location:booking.php");
}
else{
echo 'Nothing Selected Try Again';
}
}
}
}
如何解决?如何捕获选定的行以执行操作?请查看本文所附的屏幕截图,以更好地理解。我已经显示了数据库表和操作页,其中表行将要执行操作。