Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Querystring checking - how?
Old 01-05-2009, 12:23 PM Querystring checking - how?
Novice Talker

Posts: 12
Name: Noam .
Trades: 0
Hey guys, I'm building an articles system that based on querystrings.
The system gets one value (Aid=number...), checks if it numeric or not null. But if the URL doesn't contain the Aid parameter, it generates an PHP error (page.php?Aid=1 >> page.php). How can I check if it's there?

Noam
noam_moshe is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-05-2009, 12:27 PM Re: Querystring checking - how?
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
I think you should use the empty function, which checks if a variable exists and also checks if it's not null.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 12:28 PM Re: Querystring checking - how?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
if ($_GET["aid"]) {
// exists do something
} else {
// doesn't, do something else
}
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-05-2009, 12:32 PM Re: Querystring checking - how?
Novice Talker

Posts: 12
Name: Noam .
Trades: 0
Quote:
Originally Posted by Insensus View Post
I think you should use the empty function, which checks if a variable exists and also checks if it's not null.
It doesn't work because I'm basing the check through the QS (something like: isset($_GET['SearchInput']).
noam_moshe is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 12:40 PM Re: Querystring checking - how?
Novice Talker

Posts: 12
Name: Noam .
Trades: 0
Quote:
Originally Posted by chrishirst View Post
if ($_GET["aid"]) {
// exists do something
} else {
// doesn't, do something else
}
Neither.

OK, you want my code :
the global function that checks the QS:
function QSfilterW($Qid)
{

if (trim($Qid)!="" || $Qid==false)
{
$Qid=trim($Qid);
$Qid=strip_tags($Qid);
return $Qid;
}
else
{
return false;
}

}

And the 'if':
if (QSfilterW($_GET['SearchInput'])==false || $_GET['SearchInput']!=true)
{...}
noam_moshe is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 02:35 PM Re: Querystring checking - how?
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
I'd say
if (trim($Qid)!="" || $Qid==false)
should be
if (trim($Qid)!="" && $Qid!=false)
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 02:41 PM Re: Querystring checking - how?
Novice Talker

Posts: 12
Name: Noam .
Trades: 0
well you right, it's logicly right, but still prints error:
Notice: Undefined index: SearchInput in C:\wamp\www\Yeadim\ArticleSearchINC.Do.php
which is: if (QSfilterW($_GET['SearchInput'])==false || $_GET['SearchInput']!=true)
noam_moshe is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 04:17 PM Re: Querystring checking - how?
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
That's just a notice, not even a warning.
It's something you can't get rid of, unless you put it inside a [b]try/catch[b] block.

PHP by default displays all errors except for notices, because you can mostly neglect them.
This function at the top of your script will do the same:
PHP Code:
error_reporting(E_ALL E_NOTICE); 
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 04:20 PM Re: Querystring checking - how?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
this error means that the get request had no parameter ""SearchInput".
If you want to remove that notice, you should either check with isset in the if condifiotn, or initialize it before going in the if:
PHP Code:
$SearchInput=isset($_GET['SearchInput']?$_GET['SearchInput']:False
...
if (
QSfilterW($SearchInput)==false || $SearchInput!=true){


And note that it's just a notice, not an error.
It simply is mean as an informational message that PHP had to interpret what you wrote in a way that might not be the one you wanted.

like using $array[key] rather than $array['key']. In the first case, php tries to find a constant named "key", but as it doesn't finf one, fall back to look if the array have a key named "key".
You might had forgot to include the part who defined the constant.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 01-05-2009 at 04:23 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Querystring checking - how?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25666 seconds with 12 queries