如何在不提交表单的情况下显示冲突消息?

时间:2017-11-26 08:25:21

标签: php jquery html ajax

我正在构建一个主题加载系统,允许用户将受试者放入时间表,如果与其他时间表冲突,它将检测或不会保存时间表,例如:第一个时间表(ITS 111 / Room1 / MWF) / 7:00 - 8:00),第二个时间表(ITS 112 / Room1 / MWF / 7:00 - 8:00 am)。所以在我的情况下我已经做到了(这只是简单易行)但我想表明在没有点击保存按钮的情况下表格中存在冲突。

This is the form that I told you

我实际上在做这样的事情,比如使用这段代码: (这是在index.php中)

<script>
 $("#feedback").load("check.php").hide();
$("#rooms").keyup(function(){
    $.post("check.php", { room: form1.room.value }, 
        function(result){
        $("#feedback").html(result).show();
    });
});

$("#feedback2").load("check.php").hide();
$("#time").keyup(function(){
    $.post("check.php", { time: form2.time.value }, 
        function(result){
        $("#feedback2").html(result).show();
    });
});
</script>


<div class="ui-widget">
    <label for="rooms">Rooms: </label>
    <form name="form1">
        <input id="rooms" type="text" name="room">
    </form>
    <div id="feedback"></div>
</div>

<div class="ui-widget">
    <label for="time">Time: </label>
    <form name="form2">
        <input id="time" type="text" name="time">
    </form>
    <div id="feedback2"></div>
</div>

这是在check.php

<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "subject_loading_for_csit";
$con = mysqli_connect($host, $user, $password, $database) or die ("could not connect");
if (mysqli_connect_errno()) {
    echo "connection failed:".mysqli_connect_error();
    exit;
}


echo $room = $_POST['room'];
echo $time = $_POST['time'];
$rmt  = $room."".$time;

$query =  mysqli_query($con, "SELECT * FROM subject_scheduled where room_time = '$rmt' ");
$count = mysqli_num_rows($query);

if ($count == 0) {
    echo "OK";
}else if($count > 0){
    echo "Already taken";
}
?>

0 个答案:

没有答案