请查看此create_session.php应用程序:应用程序
当你打开应用程序时,你会看到一个CourseId文本框。在文本框中键入"info101",然后单击提交。
它应该显示以下所有功能。不要键入任何内容,点击底部的"准备问题"按钮。你应该看到很多红色的信息。这是一个验证,说明您需要为每个表单输入做什么。
现在填写所有功能,但对于"房间"文本框,请输入"CN10/10"。这是一个不正确的值。填写完所有详细信息后,单击"准备问题"按钮,所有红色消息都应该消失,但它应该在"房间"文本框下显示一条消息,因为值不正确,但没有显示任何消息。它应该显示消息"此房间无效"。
现在,如果您在"Room"文本框"CW5/10"中键入正确的值,并单击"Prepare Questions"按钮,那么它应该不会显示任何消息(因为我认为它没有正确使用Json,所以它会显示),但也会出现一个确认框,但这也不会发生。
所以我的问题是,为什么它没有为房间文本框做它应该做的事情。为什么房间文本框中没有显示消息?当所有功能都正确输入时,为什么没有显示确认框?
以下是相关代码(不是整个代码,只是重要代码)
function postback(callback){
if(validation()){
$.getJSON(
'/u0867587/Mobile_app/create_session.php',
{"room_no":$("#room").val()},
function(json){
$("#roomAlert").html(json.msg);
callback(json.msg);
});
}
} // should show message from php if room is valid or not
function showConfirm(){
var confirmMsg=confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards your Session." + "'n" + "'n" + "Are you sure you want to Proceed?" + "'n" );
if (confirmMsg==true)
{
submitform();
}
}
<form action="QandATable.php" method="post" id="sessionForm">
<p><strong>10: Room:</strong> <input type="text" id="room" name="roomChosen" value="<?php echo $roomChosen; ?>" />
<br/><span id="roomAlert"></span></p> <!-- Enter Room here-->
<p><strong>11: </strong><input class="questionBtn" type="submit" value="Prepare Questions" name="prequestion" onClick="myClickHandler(); return false;"/></p>
</form>
<?php
if (isset($_POST['prequestion'])) {
$roomquery = "
SELECT Room
FROM Room
WHERE
(Room = '".mysql_real_escape_string($roomChosen)."')
";
$roomnum = mysql_num_rows($roomresult = mysql_query($roomquery));
mysql_close();
if($roomnum ==0){
$msg = "This Room is Invalid";
} else {
$msg = "";
}
$d = array("msg" => $msg);
echo json_encode($d);
} // checks to see if room value in textbox matches any value in database or not
?>
<script type="text/javascript">
function myClickHandler(){
if(validation()){
postback(function(message) {
if (message == "")
showConfirm();
});
}
}
// if there is no validation errors and json message == "" (this message is displayed if there is match in database for room), then show confirmation box.
</script>
Sql没有任何问题。表的名称为"Room",但字段的名称也称为"房间"。我在room.php文件应用程序中有一个有效或无效房间的工作示例,它在我的create_session.php文件中不起作用。再次测试它,键入"CW5/10"表示有效房间,键入其他任何内容表示无效房间
我认为您的SQL请求中存在错误。您可能应该检查Room.id或Room.name,而不仅仅是Room,它似乎是您的表名。直接在phpMyAdmin中尝试您的请求。
[编辑]如果请求不好,您的php文件可能会发出错误/警告,并且响应不是JSON格式的