PDA

View Full Version : PHP Generic check of URL values



Lionelandre
11-20-2003, 03:18 PM
Hi,

I am looking to write a PHP function that would read the URL and verify that none of the values are blank. Now, granted, I could do this manually for each occurence, but I can have my usrl like this:

http://www.somesite.com/index.php3?var1=val1

or like so:

http://www.somesite.com/index.php3?RndID=12&Reference=test123456&Cat_id=1&Sub_cat1_id=2&Sub_cat2_id=2&Sub_cat3_id=2&Short_Description=sfvdsbvfsdvfds&Long_Description=vvvuuvuyufuyf&Attribute=Attribute&Maker_id=3&weight=1&Price=2&Size=5&AVAIL=1&DISPLAY=1&submit=Submit+Query

I'm sure a genius out there has written a function out there that I can reuse, right ? :)

Thanks a lot, guys.

Lionel

redcircle
11-20-2003, 03:53 PM
function check_blank($get)
{

if(is_array($get))
{
foreach($get as $key=>$value)
{
if(!isset($value))
{
$error.=$key .' has no value
';
}
}
}
if($error)
{
$error = 'ERROR: an error has occured
'.$error;
return $error;
}
}



useage would be
echo get_blank($_GET);

or an array that you would want to check. Only thing is this will fail if the value they entered is 0

Lionelandre
11-20-2003, 03:58 PM
Very cool.

I figure I could use

if ($value != ""){
.....
}

in lieu of

if(!isset($value)) {
...
}

As you can tell, I'm just getting started and I'm learning as I'm doing!

Thanksmuch!

:L

redcircle
11-20-2003, 07:25 PM
no problem.. glad I could help

trinski
12-21-2003, 12:50 PM
i'd do this:

function blankChecker() {

if($_POST['name'] == '' ||
$_POST['address'] == '') {

return 'Error: Do not leave fields blank.'
}
}

Your suggestion is way cool. More efficient, I must say. :)