1

i am getting an error of undefined index :username in php file.. what to do?

event to handel when button2 is clicked

  $("#button2").click(function(){
        var username= $("#PM_username_field").val();
        $.post('abc.php',{username: username },function(data){
        $("#error_pm_username").show().load('abc.php');
        });

    });


       <?php
        $username=$_POST['username'];
        echo $username;
       ?>
linuxeasy
  • 6,269
  • 7
  • 33
  • 40
  • 3
    You need to learn how to [READ and debug](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) error messages. Everything you needed to solve the problem was in the error message. $_POST['username'] is not set to anything – Anigel Aug 01 '13 at 12:28

1 Answers1

1

Use below code:

<?php
   if(!empty($_POST) && isset($_POST['username'])) {
       $username=$_POST['username'];
       echo $username;
   }
?>

You need to check that the form is post or not.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75