Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End undefined index: (problem)

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #33158
    dynamyc
    Member

    Hello!
    I have a search script and when i run it i receive this
    ( ! ) Notice: Undefined index: terms in search.php on line 15 and another on line 18
    This is line 15 :

    $nospaces = substr($_GET,0,4);

    and this line 18:

    if ($_GET == "") {

    I run this on my localhost (WAMP last version)

    #72599
    SgtLegend
    Member

    If the array index “terms” doesn’t exist then this error will occur, what you need to do is the following…

    if (isset($_GET) && !empty($_GET)) {
    $nospaces = substr($_GET, 0, 4);
    } else {
    // Show an error message!
    }

    This will make sure the index exists otherwise it will show an error if you want it to.

    #72600
    ddliu
    Member

    @dynamyc, I don’t think such notice is an error in the world of PHP, it’s just a notice.

    The simplest way is to ignore NOTICE in PHP:


    error_reporting(E_ALL^E_NOTICE);

    However, if you need to make it strict, follow @SgtLegend’s way.

    #72582
    ddliu
    Member

    @dynamyc, I don’t think such notice is an error in the world of PHP, it’s just a notice.

    The simplest way is to ignore NOTICE in PHP:


    error_reporting(E_ALL^E_NOTICE);

    However, if you need to make it strict, follow @SgtLegend’s way.

    #72583
    ddliu
    Member

    Sorry, duplicated post due to network issue.

    Anyone help to delete these?

    #82211
    dynamyc
    Member

    thanks guys !

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.