0

When i press F12 and look at the warnings i see a message that says

Line 18: Undefined index: task_uid

I just dont really understand why it is undefined, considering that i did declare it, and then select it, in here:

    <?php
        session_start();
        require ("../../../main/gerais/DBConn.php");
        $task_uid = $_GET['task_uid'];
        $proj_id = $_GET['proj_id'];
    ?>

This here comes three lines before the "Line 18" that is supposed to be the error, according to the console. Here is this Line:

     <?php
            if(!empty($_POST['proj_id'])||($_POST['task_uid']))
                die("Invalid proj_id or task_uid.");

            $query = "
                SELECT  pm.proj_id, pm.task_uid, etc etc etc...

      ?>

So why is it undefined? And, while i'm not sure if this question is answerable without context, but how much does it matter, considering this "task_uid" shows up in the URL, and considering it only showed up as a warning, not as a real error?

RazorFinger
  • 231
  • 2
  • 12
  • It seems that when there is no `GET` request with the `task_uid` so that error will be returned... – Bubble Hacker Jun 21 '16 at 17:54
  • 1
    you READ from it without ever checking if it actually exists, therefore you get the warning when it DOESN'T exist. e.g. if the script isn't invoked with that query parameter, you'll get the warning. empty() is not a valid test for existence. a variable can exist AND be empty simultaneously, e.g. `$foo = 0; empty($foo)` is TRUE. you need to use `isset()` which DOES check of existence, regardless of the content. – Marc B Jun 21 '16 at 17:57

1 Answers1

1

You need to use !empty on both variables:

if(!empty($_POST['proj_id'])||!empty($_POST['task_uid']))
aynber
  • 22,380
  • 8
  • 50
  • 63