Jump to content

Help with PHP code to switch phone number


PHPNEWTOIT

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.