代码忽略行数

时间:2018-01-16 18:23:27

标签: php mysql

我有一个用户发送邀请的系统,一旦官方接受,它将被保存到数据库并同步到官方的日历。

我试图运行查询,检查当前时间是否有任何事件。基本上,如果它返回至少1,则意味着邀请不会发送,因为存在冲突,但它只是忽略了MySQL数据库的行数。这是我的代码:

// variables
$id = $_GET['id'];
$dStart = $_POST['dStart'];
$dEnd = $_POST['dEnd'];
$time = $_POST['time'];
$time_end = $_POST['time_end'];

// convert them into date formats
$date = date("Y-m-d", strtotime($dStart));
$date2 = date("Y-m-d", strtotime($dEnd));
$time_f = date("H:i:s", strtotime($time));
$time_end_f = date("H:i:s", strtotime($time_end));

// set default timezone
date_default_timezone_set('Asia/Manila');
// check if date is occupied
$query_check = mysqli_query($con, "SELECT COUNT(*) as total FROM events WHERE (date_start = '$date') AND ((`time` BETWEEN '$time_f' AND '$time_end_f') OR (`time_end` BETWEEN '$time_f' AND '$time_end_f')) AND pastor_id = '$id' AND invite = 0 AND reschedule = 0") or die (mysqli_error($con));
$fetch_check = mysqli_fetch_array($query_check);
if ($fetch_check['total'] >= 1) {
    echo "<center><p>Sorry, this time is occupied. Please select another schedule</p><p>If you haven't, please refer to this pastor's calendar which can be found by <a href='profile.php?id=$id&grid=true'>clicking here.</a></p></center>";
} else {
    // generate random reference code
    $ref_code = rand(1000000, 9999999);
    $_SESSION['reference_code'] = $ref_code;
    $ref_code_final = $_SESSION['reference_code'];
    // insert to events table
    $query = mysqli_query($con, "INSERT INTO `events` (`id`, `reference_code`, `name`, `description`, `date_start`, `date_end`, `time`, `time_end`, `pastor_id`, `pastor`, `category`, `venue`, `invite`, `sender_name`, `sender_address`, `sender_phone`) VALUES (NULL, '$ref_code_final', '$name', '$description', '$date', '$date2', '$time', '$time_end', '$id', '$pastor', '$category', '$venue', '1', '$sender', '$address', '$phone')");

    header("Location: send.php?sendid=$id&success");
}

我在PHPMyAdmin上检查了很多次,查询从我的数据库返回至少1。我创建了另一个.php文件并在那里运行查询,回显结果并且仍然输出1.但由于某种原因,当我在此处使用查询时,完全忽略if statement并且去直接到else

0 个答案:

没有答案