如果text_checkin等于reserve from(reserve from是我表中的列)。再次,如果text_checkin等于reservefrom列,则浏览器将回显“相同日期”,它在第一行中运行,但是我在第二行中在reservefrom列中输入相同的数据,即使reservefrom列等于text_checkin。
结构如下:
$reservation = mysqli_query($db, "SELECT * from reservation");
//if submit is clicked
$checkin = $_POST['text_checkin'];
$sqlroom3 = "SELECT * FROM reservation";
$resultroom3 = mysqli_query($db, $sqlroom3);
$valuesroom3 = mysqli_fetch_assoc($resultroom3);
$num_rowsroom3 = $valuesroom3['reservefrom'];
if(isset($_POST['submitBtn']) && $row = mysqli_fetch_array($reservation))
{
if($row['reservefrom'] == $checkin)
{
echo "asdasd";
}
else
{
$lastname = $_POST['text_lastname'];
$firstname = $_POST['text_firstname'];
$address = $_POST['text_address'];
$tnumber = $_POST['text_tnumber'];
$cnumber = $_POST['text_cnumber'];
$email = $_POST['text_email'];
$checkin = $_POST['text_checkin'];
$checkout = $_POST['text_checkout'];
$room = $_POST['text_room'];
$tour = $_POST['text_tour'];
$guest = $_POST['text_guest'];
$query = "INSERT INTO reservation (lastname, firstname, homeaddress, telephonenumber, cellphonenumber, email, reservefrom, reserveto, room, tour, guestnumber) values ('$lastname', '$firstname', '$address', '$tnumber', '$cnumber', '$email', '$checkin', '$checkout', '$room', '$tour', '$guest')";
mysqli_query($db, $query);
echo "Data Submitted!";
}
}
最佳答案
您需要更改逻辑。
您有多个行,并且仅检查text_checkin是否等于第一个$ row ['reservefrom']。
多数民众赞成在第二行中总是插入。
您可以更改查询以仅返回所需的行,或者循环执行检查表中的所有行。
关于php - PHP和MySQL中的数据相等,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45967573/