Hi, Ok, I thought I may need to explain my stituation alittle further.
I already have a switch statement handling the functions and the if statements handle the submit buttons. I will not be passing stockId to all of the functions, it's just work in progress.
So my questions are is there a better way to code this? Whilst keeping the functionality I require? (Which is basically passing a variable to a submit/viewFaceStock etc button and displaying it in a popup.) TIA, Will.
Code: Select all
<br><br><input type="e;submit"e; name="e;submit"e; value="e;submit me!"e;>
<br><br><input type="e;submit"e; name="e;viewFaceStock"e; value="e;viewFaceStock"e;>
<br><br><input type="e;submit"e; name="e;addFaceStock"e; value="e;addFaceStock"e;>
<br><br><input type="e;submit"e; name="e;viewAdhesive"e; value="e;viewAdhesive"e;>
<br><br><input type="e;submit"e; name="e;addAdhesive"e; value="e;addAdhesive"e;>
<br><br><input type="e;submit"e; name="e;viewLiner"e; value="e;viewLiner"e;>
<br><br><input type="e;submit"e; name="e;addLiner"e; value="e;addLiner"e;>
Code: Select all
// Set Up Submit
if ($_POST['submit']) {
echo '<pre>'; print_r($_POST); echo "<h1>Submitted to DB</h1><br>"; echo "</pre>";
}
if ($_POST['viewFaceStock']) {view($_POST['stockId']);}
if ($_POST['addFaceStock']) {view($_POST['stockId']);}
if ($_POST['viewAdhesive']) {view($_POST['stockId']);}
if ($_POST['addAdhesive']) {view($_POST['stockId']);}
if ($_POST['viewLiner']) {view($_POST['stockId']);}
if ($_POST['addLiner']) {view($_POST['stockId']);}
// Set action Variable
$action = ($_GET['action']);
// Pop up function
function view($stockId) {
echo "<script language=\"javascript\">var newWindow = window.open('".$_SERVER['PHP_SELF']."?action=viewFaceStock&stockId=".$stockId."','','scrollbars=yes,status=yes,WIDTH=350,height=350')</script>";
}
// View Record Function
function fnViewFaceStock() {
html_header();
$stockId = $_GET['stockId'];
$query = "SELECT stockId, description, basisWeight, caliper FROM austock
WHERE stockId = '$stockId'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$query_data = mysql_fetch_array($result);
$stockId = $query_data["stockId"];
$description = $query_data["description"];
$basisWeight = $query_data["basisWeight"];
echo $stockId;
echo "<br>";
echo $description;
echo "<br>";
echo $basisWeight;
}
// Setup switch - View or Submit
switch($action) {
case "viewFaceStock":
fnViewFaceStock();
break;
case "addFaceStock":
fnAddFaceStock();
break;
case "viewAdhesive":
fnViewAdhesive();
break;
case "addAdhesive":
fnAddAdhesive();
break;
case "viewLiner":
fnViewLiner();
break;
case "addLiner":
fnAddLiner();
break;
default:
list_summary();
break;
}