www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Check if _GET variable exists

  1. #1
    Join Date
    Aug 2007
    Location
    New Jersey, US
    Posts
    1,779

    resolved [RESOLVED] Check if _GET variable exists

    Hi,

    So I have a page with url:
    mysite.com/product.php?model=JUCA3821

    This would bring up my JUCA3821 product.

    I'd like to make it so that if a user deleted the model part (mysite.com/product.php) it would redirect to an error page or something similar.

    So I wrote this code:

    PHP Code:
    // if model is empty, the url is incorrect
    if (!isset($_GET["model"]) || empty($_GET["model"])) {
        
    header('Location: /product-error.php');
    } else {
        
    $modelNo $_GET["model"];
    }

    $tsql "SELECT fProductRefNum1, ..., fUnitDimension2
             FROM fProducts
             WHERE fProductRefNum1 = '
    $modelNo'"
    But this isn't working. I can't seem to make it so that this will work. I get this error message:
    "PHP Notice: Undefined variable: modelNo in E:\WWW\DEV\product.php on line 19"

    I've tried every different way I can think of. Does anyone have any ideas?

    Thanks a lot,
    Dan

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    You need to exit() after sending the header to prevent the rest of the script from executing:

    PHP Code:
    header('Location: /product-error.php'); 
    exit(); 

  3. #3
    Join Date
    Aug 2007
    Location
    New Jersey, US
    Posts
    1,779
    Wow, that was simple.

    Thanks a lot Mindzai!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles