我收到此警告:
mysqli_query()期望参数2为字符串,对象在 第25行的C:\ xampp \ htdocs \ c1 \ details_save.php未知列 “字段列表”中的“ combo_id”
<?php
session_start();
include('includes/dbcon.php');
$id = $_SESSION['id'];
$venue = $_POST['venue'];
$date = $_POST['date'];
$time = $_POST['time'];
$motif = $_POST['motif'];
$pax = $_POST['pax'];
$type = $_POST['type'];
$ocassion = $_POST['ocassion'];
$cid = $_POST['combo_id'];
$date=date("Y-m-d",strtotime($date));
$query = mysqli_query($con, "SELECT * FROM `reservation` WHERE r_date='".$date."' AND r_status = 'Approved'");
if(mysqli_num_rows($query) > 0)
{
echo "<script>alert ('Date is already reserved');
window.history.back(); </script>";
}
else{
if (!mysqli_query($con,$query))
{
$query = mysqli_query($con, "SELECT * FROM combo WHERE combo_id='$cid'");
$row=mysqli_fetch_array($query);
$price=$row['combo_price'];
$payable=$pax*$price;
mysqli_query($con,"UPDATE reservation SET payable='$payable',balance='$payable',r_venue='$venue',r_date='$date',r_time='$time',r_motif='$motif',r_ocassion='$ocassion',r_type='$type',pax='$pax',combo_id='$cid',price='$price' where rid='$id'")or die(mysqli_error($con));
$_SESSION['id']=$id;
echo "<script>document.location='payment.php'</script>";
}}
?>
答案 0 :(得分:0)
您需要按以下方式更改代码:
session_start();
include('includes/dbcon.php');
$id = $_SESSION['id'];
$venue = $_POST['venue'];
$date = $_POST['date'];
$time = $_POST['time'];
$motif = $_POST['motif'];
$pax = $_POST['pax'];
$type = $_POST['type'];
$ocassion = $_POST['ocassion'];
$cid = $_POST['combo_id'];
$date = date("Y-m-d", strtotime($date));
$selectQuery = "SELECT * FROM `reservation` WHERE r_date='" . $date . "' AND r_status = 'Approved'";
$query = mysqli_query($con, $selectQuery);
if (mysqli_num_rows($query) > 0) {
echo "<script>alert ('Date is already reserved');
window.history.back(); </script>";
} else {
// if (!mysqli_query($con, $selectQuery)) { // no need to apply this condition
$query = mysqli_query($con, "SELECT * FROM combo WHERE combo_id='$cid'");
$row = mysqli_fetch_array($query);
$price = $row['combo_price'];
$payable = $pax * $price;
mysqli_query($con, "UPDATE reservation SET payable='$payable',balance='$payable',r_venue='$venue',r_date='$date',r_time='$time',r_motif='$motif',r_ocassion='$ocassion',r_type='$type',pax='$pax',combo_id='$cid',price='$price' where rid='$id'")or die(mysqli_error($con));
$_SESSION['id'] = $id;
echo "<script>document.location='payment.php'</script>";
// }
}
?>
您不需要检查if(!mysql_query($con, $query))
。您可以简单地在其他条件下编写代码。希望对您有帮助。