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条)

报告相同问题?