Page 1 of 1

Switch / isset assistance

Posted: Wed May 25, 2005 6:55 pm
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;
   }

Posted: Wed May 25, 2005 7:19 pm
by Skara

Code: Select all

$action = isset($_GET['action']) ? $_GET['action'] : '';

Posted: Wed May 25, 2005 8:41 pm
by John Cartwright
better yet, use !empty() to make sure your variable has atleast a value.