Jayant Jt Hirani
Jayant Jt Hirani

Reputation: 5

Keep getting this notice error cms

Hi im making a CMS with responsive HTML5 front this part of the code retrieves the relevant information from url so that the relevant information can be displayed

this is the notice i am getting

Notice: Undefined index: pid in /home/hj016/public_html/SSTW/index.php on line 7

    require_once "script/connect_to_mysql.php";
// Determine which page ID to use in our query below
    if (!$_GET['pid']) {
        $pageid = '1';
    } else {
        $pageid = ereg_replace("[^0-9]", "", $_GET['pid']); 
// filter everything but numbers for security
    }

is there any way to hide this ??

Upvotes: 1

Views: 637

Answers (3)

owenmelbz
owenmelbz

Reputation: 6574

 require_once "script/connect_to_mysql.php";
    // Determine which page ID to use in our query below
    if (!isset($_GET['pid']) || empty($_GET['pid'])) {
        $pageid = '1';
    } else {
        $pageid = ereg_replace("[^0-9]", "", $_GET['pid']); 
    // filter everything but numbers for security
    }

hows that? will make sure its set and not set to just like pid=

Upvotes: 0

juco
juco

Reputation: 6342

On a production server you would generally hide notices anyway. But checking using isset($_GET['pid']) would be the preferred approach.

Upvotes: 1

j_mcnally
j_mcnally

Reputation: 6958

try

if (!isset($_GET['pid'])) {

basically you are calling for an undefined index even though you are trying to check if its not defined. The safe way to do this is with isset as it wont error if its not defined, because your checking existence not value.

Upvotes: 1

Related Questions