Re: Re: Question re empty query

From: Date: Thu, 10 Mar 2005 20:23:16 +0000
Subject: Re: Re: Question re empty query
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-210463@lists.php.net to get a copy of this message
Jackson Linux wrote:
all you need is 1 if (or if/else) statement, note that my example is the logical reverse of the first if statement I posted (in reply to your question): if (!isset($_GET['r']) || empty($_GET['r']) || !($r = intval($_GET['r']))) {
    // _GET['r'] is either not set, empty or not a positive int greater  than zero.
        // the required var is 'bad' so lets redirect the user.
    if (!headers_sent()) {
        header('location: /yourRvarsucks.php');
    } else {
        // you'll have to figure out what to do yourself
        // if you want to redirect and headers have already been sent!
           }
    exit;
} // now comes the rest of the script (build SQL, run it, output the data) $where = "WHERE cvjobcats.cv_id=cv.cv_id
      AND cvjobcats.jobcat_id = '$r'
          AND jobcat.jobcat_id=cvjobcats.jobcat_id";
$sort = "ORDER BY cv.sort"; // etc etc ...
Whhooo. I created this: $badr = "" ) 1. I believe that this: if (!isset($_GET['r']) || empty($_GET['r']) || !($r = intval($_GET['r']))) {
    // _GET['r'] is either not set, empty or not a positive int greater  than zero.
        // the required var is 'bad' so lets redirect the user.
    if (!headers_sent()) {
        header('location: {$_SERVER['PHP_SELF']}#bookmark');
    } else {
        // you'll have to figure out what to do yourself
        // if you want to redirect and headers have already been sent!
           }
    exit;
} should kick back anyone who uses a bad or no $r to the location: {$_SERVER['PHP_SELF']}#bookmark However two problems: 1. This is dumb, I'm sure, but when I test this on its own it loops into a constant redirect, as the page reloads itself (PHP_SELF), hits the header location and tries again. I want it to keep the same page name (file.htm) but load a conditional menu if the request is for a non-existent or bad $r 2. Mustn't I also speficy what to do in the event that the $r is good?
thats up to you, I thought that was the whole point.
Would that be just continuing the script: if (isset($_GET['r'])) {
    if(!empty($_GET['r']) && ($r = intval($_GET['r']))){
    } else {
        // And if so, then why do I need the IF statement here at all?  Shouldn't this be a WHILE?
    }
} // now comes the rest of the script (build SQL, run it, output the data)
do you know include()? http://php.net/include if (!isset($_GET['r']) || empty($_GET['r']) || !($r = intval($_GET['r']))) { // show a list of R's include('showlist.inc.php'); } else { // process an R include('process.inc.php'); }
??


« previous php.general (#210463) next »