我有一个表单,当您单击按钮时应该将数据添加到表中,然后弹出一个窗口,告诉您它已添加或出现问题。用户可以将数据放入文本区域并单击速率框会出现并告诉您它已添加但当我查看表格时它尚未添加。浏览完代码后,我看不到任何突然出现的东西。
这是表格
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<form id="add-rateing">
<input type="text" name="MOVIE_ID">
<input type="text" name="USER_ID">
<input type="submit" value="rate">
</form>
<script type="text/javascript">
$("#add-rateing").submit(function(){
event.preventDefault()
addrateing();
});
function addrateing()
{
var movie_id_s = $("#add-rateing [name='MOVIE_ID']").val();
var user_id_s = $("#add-rateing [name='USER_ID']").val();
var errors = '';
$.ajax({
type : "GET",
url : "movie_watched.php",
data : { movie : movie_id_s,
user : user_id_s, },
cache : false, timeout: 10000,
success : function() {
alert("added");
},
error : function() {
alert("there is a problom");
},
complete : function() {
}
});
};
</script>
</body>
</html>
这是movie_watched.php
<?php
include"scripts/connect.php" ;
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$movie = mysql_real_escape_string($_POST['MOVIE_ID']);
$user = mysql_real_escape_string($_POST['USER_ID']);
$error = '';
$query=mysql_query"INSERT INTO rateing (movie_id, user_id) VALUES ('".$movie."', '".$user."')";
if (!mysql_query($query, $conn))
{
$error = mysql_error();
$return['error'] = $error;
echo json_encode($return);
mysql_close($conn);
}
else
{
$success = "Thank you for playing";
$return['mysql'] = $success;
echo json_encode($return);
mysql_close($conn);
}
?>
谢谢你。