FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » PHP discussions » Newbie Question - Ignore missing ? links in URL
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Newbie Question - Ignore missing ? links in URL [message #33566] Thu, 07 September 2006 16:01 Go to next message
rgraylint is currently offline  rgraylint   United States
Messages: 2
Registered: September 2006
Location: US
Karma: 0
Junior Member
I'm using links (correct term?) in the URL to pass in data. For example: www.site.com/index.php?phone=555-1212

Everything works fine when I use the following code and pass in a 'phone' value as above.
<?php
$ph = $_GET['phone'];
echo $ph;
?>

The problem is I don't always want to require a 'phone' value in the URL. If someone visits the page with: "www.site.com/index.php" I get this error complaining about the attempt to $_GET the 'phone' value when none exists:

Notice: Undefined index: e in p:\WWW\site.com\index.php on line (##)

I'm trying to make the page work (without errors) even if the URL doesn't contain the 'phone' link value it is expecting. I need a way to test if the 'phone' value was passed in with the URL before I try to assign it to a variable. Is this possible?

Thanks for your help! - Robert
Re: Newbie Question - Ignore missing ? links in URL [message #33567 is a reply to message #33566] Thu, 07 September 2006 16:23 Go to previous messageGo to next message
rgraylint is currently offline  rgraylint   United States
Messages: 2
Registered: September 2006
Location: US
Karma: 0
Junior Member
I did find a solution that I don't like. I can add this line of code to suppress errors in this file.

error_reporting(E_ALL ^ E_NOTICE); // Turns off errors just for this file. Avoids changing error setting in the php.ini global file.

It does make my problem go away. I can remove the 'phone' link entry from the URL and I don't get any errors. I just don't like it because it feels like cheating. Smile

If there is a way to programaticly test for the existence of the 'phone' link, I'd much rather do that.

Again, thanks for your help...

- Robert
Re: Newbie Question - Ignore missing ? links in URL [message #34258 is a reply to message #33566] Mon, 16 October 2006 13:08 Go to previous message
sBForum is currently offline  sBForum   Jordan
Messages: 5
Registered: October 2006
Location: Jordan
Karma: 0
Junior Member

easily , put this :

$ph = (isset($_GET["phone"] ? $_GET["phone"] : 0);
echo $ph;


if it's not set in the URL address it'll make the $ph value equals zero . u can replace 0 with '' to make it empty when it's not identified ..

anyway , this is the way i use , there r more methods as i think but this is good enough for this use .. Very Happy Very Happy

anything else ?

regards,
sBForum Shocked
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: how to add javascript in php
Next Topic: need help. please!
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 10:16:51 GMT 2024

Total time taken to generate the page: 0.02464 seconds