PHPNEWTOIT Posted January 13, 2009 Share Posted January 13, 2009 Hi I am stuggling with code to change the phone number displayed on the website depedning on the incoming link. For example the incomings links will be like this:- http://www.mysite.com/index.php?a=1 http://www.mysite.com/index.php?a=2 http://www.mysite.com/index.php?a=3 It work ok until someone uses no incoming link for example http://www.mysite.com/index.php any ideas how I can fix this please. Notice: Undefined variable: referer in C:\Program Files\EasyPHP 2.0b1\www\y3kdemo\templates\track.php on line 10 Notice: Undefined variable: referer in C:\Program Files\EasyPHP 2.0b1\www\y3kdemo\templates\track.php on line 13 default no to show <?php $phoneno = 'somedefaultvalue'; if(isset($_GET['a'])) { $referer = $_GET['a']; } switch($referer) { case '1': $phoneno = 'phone for campaign 1'; break; case '2': $phoneno = 'phone for campaign 2'; break; default: $phoneno = 'default no to show'; break; } echo $phoneno; ?> Many thanks for your help. Roy Link to comment https://forums.phpfreaks.com/topic/140671-help-with-php-code-to-switch-phone-number/ Share on other sites More sharing options...
rhodesa Posted January 13, 2009 Share Posted January 13, 2009 <?php $referer = isset($_GET['a']) ? $_GET['a'] : null; switch($referer) { case '1': $phoneno = 'phone for campaign 1'; break; case '2': $phoneno = 'phone for campaign 2'; break; default: $phoneno = 'somedefaultvalue'; } echo $phoneno; ?> Link to comment https://forums.phpfreaks.com/topic/140671-help-with-php-code-to-switch-phone-number/#findComment-736186 Share on other sites More sharing options...
kenrbnsn Posted January 13, 2009 Share Posted January 13, 2009 You should only do the switch if $_GET['a'] is set: <?php if (isset($_GET['a'])) { switch ($_GET['a']) { case '1': $phoneno = 'phone for campaign 1'; break; case '2': $phoneno = 'phone for campaign 2'; break; default: $phoneno = 'default no to show'; } } else $phoneno = 'default no to show'; echo $phoneno; ?> Ken Link to comment https://forums.phpfreaks.com/topic/140671-help-with-php-code-to-switch-phone-number/#findComment-736187 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.