gpt4 book ai didi

php - 如何验证来自数据库的多个输入?

转载 作者:行者123 更新时间:2023-11-28 23:40:01 25 4
gpt4 key购买 nike

<分区>

我不想创建验证,如果 DATE、TIME 和 COTTAGE 已经保留/可用,请检查数据库。如果这三个中的任何一个不可用,它将保存到数据库中。

这是我编写的代码:

<?php
require_once("config.php");
require_once("includes/inputs.php");

//fetching the data of the cottage
$sql = "SELECT * FROM cottage WHERE id='$cottage'";
$result = mysqli_query($link, $sql);
$row = mysqli_fetch_array($result);
$name_cottage = $row["name"];

//fetching the data of the time
$sql = "SELECT * FROM rate WHERE id='$daytime'";
$result = mysqli_query($link, $sql);
$row = mysqli_fetch_array($result);
$daytime_name = $row["name"];

//validating whether the date, time and cottage is already available in the cottage
$validate = "SELECT * FROM reserve WHERE date = '$date' AND daytime = '$daytime' AND cottage = '$cottage'";
$qry = mysqli_query($link, $validate);
$getrow = mysqli_num_rows($qry);

if( $getrow > 0 ){
echo " $date, $daytime_name and $name_cottage has already been taken!";
return false;
}
else{
$sql = "INSERT into reserve (name, address, contact, email, date, time, ahc, chc, cottage, promo, total) values ('$name','$address','$contact', '$email', '$date', '$daytime', '$ahc', '$chc', '$cottage', '$promo', '$calc')";
$result = mysqli_query($link,$sql);
echo " $date, $daytime_name and $name_cottage is successfully reserved!";
return true;
}
?>

但是我有一个错误:

警告:mysqli_num_rows() 期望参数 1 为 mysqli_result,第 22 行 C:\xampp\htdocs\reservation\formup.php 中给出的 bool 值

第22行是

$getrow = mysqli_num_rows($qry);

但是当我使用这个多选查询时:

  $validate = "SELECT * FROM reserve WHERE date = '$date'";
$validate = "SELECT * FROM reserve WHERE daytime = '$daytime'";
$validate = "SELECT * FROM reserve WHERE cottage = '$cottage'";

它会保存到数据库但是当山寨在数据库中有相同的山寨时它不会保存...

请帮我解决这个问题....

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com