2

I have write the code as:

 // session_start();
 $auid = isset($_POST['auid']) ? $_POST['auid'] : $_SESSION['auid'];
 $pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd'];

Getting error

Notice: Undefined index: auid, pwd

What is substitute of isset() in this case? Assume the code is being called without any initialization or the first calling code of application.

Based upon this short syntax, the value can only be passed of either of these two index variables.

Muhammad Muazzam
  • 2,810
  • 6
  • 33
  • 62
  • isset() is working just fine, you just didn't apply the same logic to $_SESSION indexes – Calimero Nov 26 '15 at 11:44
  • 1
    Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Ben Nov 26 '15 at 11:47

2 Answers2

4

Try:

$auid = isset($_POST['auid']) ? $_POST['auid'] : isset($_SESSION['auid']) ? $_SESSION['auid'] : '' ;
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : isset($_SESSION['pwd']) ? $_SESSION['pwd'] : '' ;
Ashish Choudhary
  • 2,004
  • 1
  • 18
  • 26
  • If the issue is not related to current nature then you can accept this as an answer and start a new question. This will help others to see your new issue and multiple people can contribute to it – Ashish Choudhary Nov 26 '15 at 12:21
  • The issue is related to session variable value on another page, looking into this. – Muhammad Muazzam Nov 26 '15 at 12:49
  • The issue is, there should be nothing in the variables if its calling first time but the error should goes as well. So assigning space is creating issue. – Muhammad Muazzam Nov 26 '15 at 13:02
  • I dont understand. Where have we assigned `space`? `''` is not a space, its a string with length 0 means its a blank string. Space will be like `' '`. Also what issue are we talking about here. Kindly be more descriptive when you say 'issue'. Issue is a vast word and can be anything. – Ashish Choudhary Nov 26 '15 at 14:17
  • No value should be set into variables other than values of index variables – Muhammad Muazzam Nov 26 '15 at 15:10
  • if no value is assigned then variables will be undefined. You can apply the logic where you are using these variables such as `if(!empty($auid)) { //use variable }` – Ashish Choudhary Nov 26 '15 at 15:38
  • there are two steps to resolve any issue. 1. Find where exactly the error is and whats causing it. 2. What can be done to resolve it. We cannot say that the error should go. The error in your original question is gone. Now you need to learn from it and apply it. If any other error is coming then it's because your other code is not handled properly. – Ashish Choudhary Nov 26 '15 at 15:44
1

Based upon @Ashus logic, the revised solution is:

$auid = isset($_POST['auid']) ? $_POST['auid'] : (isset($_SESSION['auid']) ? $_SESSION['auid'] : '');
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : (isset($_SESSION['pwd']) ? $_SESSION['pwd'] : '');
Muhammad Muazzam
  • 2,810
  • 6
  • 33
  • 62