0

我得到从 Javascript 发送的变量的 0(零)值

$query= "SELECT Name,Lastname FROM %s s, %s v, %s k WHERE s.FK_ID_user=%d AND s.Reg_id=%d AND s.Reg_id=k.Reg_id
     AND v.ID_user= s.FK_ID_user AND DATE(s.Time) BETWEEN '%d-%d-%d' AND '%d-%d-%d'";
$query = sprintf($query,$_SESSION['SESS_MAIN_BASE'],$_SESSION['SESS_USER_BASE'],$_SESSION['SESS_REG_BASE'],$id_user,$reg_id,$d_year1 ,$d_month1,$d_day1,$d_year2,$d_month2,$d_day2);

来自 Javascript:

$.ajax({
                  type: 'POST',
                  url: 'history.php',
                  data: {
                  'id_user':$('#select-choice-user').val(),
                  'reg_id':$('#select-choice-reg').val(),
                  'd_year1':$('#select-choice-year1').val(),
                  'd_month1':   $('#select-choice-month1').val(),
                  'd_day1':$('#select-choice-day1').val(),
                  'd_year2':$('#select-choice-year2').val(),
                  'd_month2':   $('#select-choice-month2').val(),
                  'd_day2':$('#select-choice-day2').val()
                  },
                  success: function(data)//callback to be executed when the response has been received
                });

这是 PHP 部分:

$id_user= $_POST['id_user'];
$reg_id= $POST['reg_id'];
$d_year1=$POST['d_year1'];
$d_month1=$POST['d_month1'];
$d_day1=$POST['d_day1'];
$d_year2=$POST['d_year2'];
$d_month2=$POST['d_month2'];
$d_day2=$POST['d_day2'];

问题是使用 POST 值发送的所有值都设置为 0,我可以在 post 方法中看到数据正常发送,值如下所示:

id_user:0010282658
reg_id:951
d_year1:2012
d_month1:05
d_day1:7
d_year2:2012
d_month2:10
d_day2:6
4

1 回答 1

8

确保您从 $_POST 而不是 $POST 读取

于 2012-10-19T18:43:29.147 回答