Undefined index in PHP post

后端 未结 3 1080
鱼传尺愫
鱼传尺愫 2021-01-26 02:43

I take a form and do variable checking in jquery then pass it to a php file in ajax but I am getting this notice

Notice: Undefined index: your_name in C:\\xampp\\htdocs\

相关标签:
3条回答
  • 2021-01-26 03:25

    not seen any issue in your js code but your php code have lil flaw

     <?php
    include 'inc/class.phpmailer.php';
    
    //it can be like that or
    if(!isset($_POST['your_name'])){
        echo "something is wrong here"; 
    }
    else{
        $your_name=$_POST["your_name"]; 
    }
    

    Note: PHP Error handling should be properly done or you can disable the php warnings

    0 讨论(0)
  • 2021-01-26 03:33

    $_POST['your_name'] cannot be assigned to the variable $your_name when the "your_name" isn't posted cause it doesn't exist .. you have to check if it exists first and then assign it to the variable .. the code should be like the following :

    if (isset($_POST['your_name'])) {
       $your_name = $_POST['your_name'];
    }
    else { 
       echo "something is wrong here";
    }
    
    0 讨论(0)
  • 2021-01-26 03:45

    You are getting value of your_name first and then checking if it exists

    $your_name=$_POST["your_name"];  <--- this line should be inside an if isset
    if(!isset($_POST['your_name'])){
    

    Do something like the following

    if (isset($_POST['your_name'])) {
       $your_name = $_POST['your_name'];
       // do whatever here
    }
    
    0 讨论(0)
提交回复
热议问题