0

我需要通过 ajax 插入数据,我有两个页面,一个是带有图标的表单,我单击它并将我发送到其他页面并插入新数据

这里是ajax代码

<script type="text/javascript">
$(function() {
  $("#dialog1").click(function() {
        $('#welcome').slideToggle('#loginhandle'); 
        $('#loginhandle').show("slow");

      var name = $("input#ausers_ID").val();
      var dataString = 'ausers_ID='+ ausers_ID  ;
        $.ajax({
               type: "POST",
               url: "OpenCashier.php",
               data: dataString,
               success: function(msg) {
                 $('#loginhandle').slideToggle('#msgreturn');
                 $('#msgreturn').show("slow");
                 $('#msgreturn').html(msg)
                .hide()
                .fadeIn(1500, function() {
        });
      }
     });
    return false;
    });


});
</script>

当我点击这个底部

<input type="submit" id="dialog1" name="dialog1" value="Insert" />  

我们必须调用这个页面

<? session_start();
include("sec.php");
include("../include/connect.php");
include("../include/safe.php");

    if($_POST["dialog1"]){

            // Every thing is OK    
            $ausers_ID=$_POST["ausers_ID"];
            $cashiers_CashierOpenDate=date('Y/m/d');
            $query="INSERT INTO `cashiers` ( `cashiers_CashierID` , `cashiers_CashierOpenDate` , `cashiers_User` , `cashiers_Status` , `cashiers_Delete`  ) VALUES ('', '$cashiers_CashierOpenDate', '$ausers_ID', '0','0');";
            mysql_query($query);
            $num=mysql_affected_rows();         
            if($num==1)
                $message="Account was added successfully";
            else                
                $message=$_POST["dialog1"]." Account is already exists in database";
    }
?>

但是数据不能插入为什么!!!

4

1 回答 1

0

您错过了包含 PHP 代码中使用的“dialog1”参数。

我建议将您的数据更改为发送到:

var dataString = {ausers_ID : ausers_ID, dialog1 : true}
于 2012-10-26T13:21:08.120 回答