Switch / isset assistance

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Switch / isset assistance

Post by facets »

Hi Gang,

I'm getting the following error :
Undefined variable: action in auaddsummary.php on line 250

I fixed most of these with if (isset) code but not $action

Also, is there a more efficent way to code the following?
Could these all be in a switch?

TIA, Will.

Code: Select all

//Receive click from buttons

if (isset($_GET['action'])) {
	$action = ($_GET['action']);
}

if (isset($_POST['addSummary'])) {
        echo '<pre>'; print_r($_POST); echo "<h1>Submitted to DB</h1><br>"; echo "</pre>";
        } 

if (isset($_POST['viewFaceStock'])) {
        view($_POST['stockId']);
}

if (isset($_POST['addFaceStock'])) {
        viewAddFaceStock();
}

// Action popup code

echo "<script language=\"javascript\">var newWindow = window.open
('".$_SERVER['PHP_SELF']."?action=viewFaceStock&stockId=".$stockId."','',
'scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
}

// Switch 
switch($action) {
    case "viewFaceStock": fnViewFaceStockSpec(); break;
    case "viewAddFaceStock": fnAddFaceStock(); break; 
    case "viewAdhesive": fnViewAdhesive(); break;
    case "addAdhesive": fnAddAdhesive(); break;
    case "viewLiner": fnViewLiner(); break;
    case "addLiner": fnAddLiner(); break;
    case "addFs": fnCreateFs(); break;   
    case "addFaceStock": viewAddFaceStock(); break;
    default: viewFaceStockSummary(); break;
   }
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Code: Select all

$action = isset($_GET['action']) ? $_GET['action'] : '';
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

better yet, use !empty() to make sure your variable has atleast a value.
Post Reply