我想将表单提交到 php,然后数据将更新到数据库并显示警报框。现在,数据已经更新了数据库,但警告框没有出现。我的代码有什么问题??谢谢。
测试.html
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function SubmitForm() {
var category_id = $("#category_id").val();
var category_name = $("#category_name").val();
$.post("test.php", { category_id: category_id, category_name: category_name },
function(data) {
alert("Finish!");
});
}
</script>
</head>
<body>
<form action="test.php" method="post">
category_id: <input type="text" name="category_id" id="category_id"/>
category_name: <input type="text" name="category_name" id="category_name"/>
<input type="button" id="searchForm" onclick="SubmitForm();" value="Send" />
</form>
</body>
</html>
测试.php
<?php
$a = $_POST['category_id'];
$b = $_POST['category_name'];
$link = mysql_connect('localhost','root','');
mysql_select_db("fyp", $link);
$sql = "INSERT INTO category (CID, Category) VALUES (".
PrepSQL($a) . ", " .
PrepSQL($b) . ")";
mysql_query($sql);
function PrepSQL($value)
{
// Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
?>