dsapkqaduj6718493 2014-01-14 02:46 采纳率: 100%
浏览 74
已采纳

PHP只读取一个$ _POST值

I am using AJAX to send some variables to a PHP form that will process them and put them into session variables. In the code below, I am trying to get data from two POST variables.

If I leave both as they are, none will work. If I comment out one, the other will work, and vice versa. I'm not sure what I'm doing wrong here.

Here is the AJAX that sends data to the PHP page to be processed:

$.ajax({
         type: 'POST',
         async: false,
         data:
             {
                 from_date: from_date,
                 job_no: job_no,
             }, 
         url: 'pnf_post.php', //send variables to this page to be processed
         success: function(data){  
             oTable2.fnReloadAjax('FE_resolved_pnfs.php'); //reload datatables
            },
         error: function(){
             console.log(data);
             alert('Error');
            }

        });  

Here is the code that processes the AJAX data:

session_start();

if(isset($_POST['job_no']))
    {
        $_SESSION['Job_Num'] = $_POST['job_no'];
        $_SESSION['Search_By_Date'] = "NO";
    }

if(isset($_POST['from_date']))
    {
        $_SESSION['From_Date'] = $_POST['from_date'];
        $_SESSION['Search_By_Date'] = "YES";  
    }                      

Any help would be greatly appreciated

  • 写回答

2条回答 默认 最新

  • doutanggun9816 2014-01-14 02:56
    关注
    1. You have set both from_date and job_no in the post data
    2. You check if key from_date or job_no exists
    3. Obviously they both exist
    4. You set Search_By_Date first to NO then to YES so it's always YES

    You might want to check if the value evaluates to true or false instead of using isset which checks the existence of the key in the array.

    @jk. Trailing comma is not a problem for modern browsers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?