0

This is the part of my code giving the problem.I tried to use isset but i think my syntax is incorrect. I still get the Notice: Undefined index: id.

if($_GET['id'] && $record['allusers'] != "Y"){
        $q2 = mysql_query("SELECT * from users WHERE alljobs = 'Y'");
        while($arr2 = mysql_fetch_assoc($q2)){
            $userjobs2[] = $arr2['id']; 
        }
Webjunkie
  • 41
  • 7
  • 1
    I don't see where you are using `isset()`. – Mike Brant Jan 21 '15 at 14:34
  • `if(isset($_GET['id']) &&` – Steve Jan 21 '15 at 14:34
  • It seems your $_GET["id"] is not exists. Create a check, is that key exists. `if (isset($_GET["id"]) ...` – vaso123 Jan 21 '15 at 14:34
  • **Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).** They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). **Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement)** instead, and **use [PDO](http://us1.php.net/pdo).** – Jay Blanchard Jan 21 '15 at 14:35

2 Answers2

0

Your code is correct this is not an Error it is a Notice to get rid of this you can use isset($_GET['id'])

if(isset($_GET['id']) && $record['allusers'] != "Y"){
        $q2 = mysql_query("SELECT * from users WHERE alljobs = 'Y'");
        while($arr2 = mysql_fetch_assoc($q2)){
            $userjobs2[] = $arr2['id']; 
        }
}
cmorrissey
  • 8,493
  • 2
  • 23
  • 27
0

$_GET['id'] won't return boolean. It will throw error if undefined/unset. Use isset().

if(isset($_GET['id']) && $record['allusers'] != 'Y') {
    // code...
}
mehulmpt
  • 15,861
  • 12
  • 48
  • 88