-1

I have a mysql table with 'user_name' and 'user_round'. I want the 'user_round' to be set to whatever the value of 'Level' (this is a javascript variable). My code brings up errors like POST 404 not found. Here is what I have:

<script type="text/javascript" src="jQuery.js"></script>
var <?php echo $_SESSION['user_name']; ?>; //Without this I get username not defined error?
var Level =  1;
function Fail() {
$.ajax({
   type: "POST",
   url: "phpfiles/savestage.php",
   data: {
      name: '<?php echo $_SESSION['user_name']; ?>',
      stage: Level
   },
   success: function() {
       console.log("Finished uploading stage");
   }
});

Here is my php page:

<?php 
  include 'connect.php';

  $sql="INSERT INTO DB NAME (user_round, user_name) VALUES ('$stage', '$name')";

  $result = mysql_query($sql, $cn) or
        die(mysql_error($cn));
?>
4

1 回答 1

0

我在这里做了一个测试,检查员说 ajax 发布的变量 Level 值为 1

<script>
var Level =  1;
function Fail() {
$.ajax({
type: "POST",
url: "phpfiles/savestage.php",
data: {
name: 'test_name',
stage: Level
},
success: function() {
console.log("Finished uploading stage");
}
});
}
Fail();
</script>   
于 2013-09-30T20:29:14.620 回答