Sorry for the lengthy post.
This script works in all respects, except that $recName is not being inserted into the DB. Hopedully some fresher eyes can help me out.
I've attempted: $GLOBALS["recName"],
global $recName, and also making $recName a session variable, still no luck.
As always, any thoughts or ideas are appreciated,
Pete
This script works in all respects, except that $recName is not being inserted into the DB. Hopedully some fresher eyes can help me out.
I've attempted: $GLOBALS["recName"],
global $recName, and also making $recName a session variable, still no luck.
As always, any thoughts or ideas are appreciated,
Pete
Code:
<?php
include("../../include/phpClasses/MyConnect.php");
/*
if( $sessionAccessLevel != 1 )
{
header("Location: UserOptionsPage.php");
}
*/
$num = $tfNum;
$recName = $tfRecipeName;
function getIngredients()
{
$dbConn = new MyConnect();
$sql = "SELECT DISTINCT ingredient_id, ingredient, gross_cost from ingredient ORDER BY ingredient";
$rs = mysql_query($sql, $dbConn->conn)or die("Connection to DataBase failed");
for($i = 0; $i < mysql_num_rows( $rs ); $i++)
{
$tmp = mysql_fetch_row( $rs );
print("<OPTION value=\"$tmp[0]:$tmp[1]:$tmp[2]\">$tmp[1]</OPTION>\n");
}
}
function getPortionSize()
{
$dbConn = new MyConnect();
$sql = "SELECT DISTINCT portion_conversion, portion_type from measurement";
$rs = mysql_query($sql, $dbConn->conn)or die("Connection to DataBase failed");
for($i = 0; $i < mysql_num_rows( $rs ); $i++)
{
$tmp = mysql_fetch_row( $rs );
print("<OPTION value=\"$tmp[0]\">$tmp[1]</OPTION>\n");
}
}
?>
<HTML>
<HEAD>
<TITLE>
</TITLE>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function shiftCost()// called by event clicking "doCost" button
{
var total = 0;
var unit = 0;
var sellAt;
var goal = 35.00;
var netCost = 0;
for(i = 0; i < ( (frmAddAndCost.length -5) / 5 ); i++)
{
unit = document.frmAddAndCost.elements["tfUnit" + i].value;
amount = document.frmAddAndCost.elements["selPortionSize" + i].value;
cost = document.frmAddAndCost.elements["selIngredient" + i].value.split(":");
netCost = (unit * amount) * cost[2];
document.frmAddAndCost.elements["tfItemCost" + i].value = netCost;
total += parseFloat(document.frmAddAndCost.elements["tfItemCost" + i].value);
sellAt = parseFloat((total/goal)*100);
document.frmAddAndCost.elements["tfTotalItemCost"].value = Math.round( total * 100 ) / 100;
document.frmAddAndCost.elements["tfSellPrice"].value = Math.round( sellAt * 100) / 100;
}
}
</SCRIPT>
</HEAD>
<BODY>
<IMG SRC="images/msrg.gif" WIDTH="452" HEIGHT="48" ALT="" BORDER="0">
<BR>
<BR>
<BR>
<? echo "<b><center>Recipe Definition for<br><font color=\"red\" size=\"+2\">$recName</font><br></center></b>";?>
<TABLE ALIGN="center" BGCOLOR="#f1cb85" CELLPADDING="2" CELLSPACING=
"2" WIDTH="99%">
<TR>
<TD WIDTH="20%" ALIGN="left">
<FONT COLOR="blue" SIZE="+1">Amt</FONT>
</TD>
<TD WIDTH="20%" ALIGN="LEFT">
<FONT COLOR="blue" SIZE="+1">Unit</FONT>
</TD>
<TD WIDTH="20%" ALIGN="LEFT">
<FONT COLOR="blue" SIZE="+1">Ingredient</FONT>
</TD>
<TD WIDTH="20%" ALIGN="RIGHT">
<FONT COLOR="blue" SIZE="+1">Description</FONT>
</TD>
<TD WIDTH="20%" ALIGN="right">
<FONT COLOR="blue" SIZE="+1">Cost</FONT>
</TD>
</TR>
</TABLE>
<TABLE ALIGN="center" id="costTable" WIDTH="90%">
<?php
if( $tfNum <= 0 )
{
echo "<br><br>";
echo "<form action=\"$PHP_SELF\" method=\"post\" name=\"frmSetIngredientLength\" id=\"frmSetIngredientLength\">";
echo "<br>Recipe Name:<input type=\"text\" name=\"tfRecipeName\" id=\"tfRecipeName\" size=\"50\" maxlength=\"50\">
echo "<BR>Number of ingredients for this recipe:<input type="text\" name=\"tfNum\" size=\"2\" maxlength=\"2\" value=\"$num\">";
echo "<br><input type=\"submit\" name=\"buildForm\" value=\"Build Form\">";
echo "</FORM>";
}
elseif(isset($buildForm))
{
echo "<FORM ACTION=\"$PHP_SELF\" METHOD=\"post\" NAME=\"frmAddAndCost\">\n\n";
for( $i = 0; $i < $num; $i++)
{
echo "<TR>\n<TD ALIGN=\"left\" WIDTH=\"5%\"><input type=\"text\" name=\"tfUnit$i\" size=\"5\" maxlength=\"5\">\n</td>\n";
echo "<TD ALIGN=\"justify\" WIDTH=\"5%\">\n<SELECT NAME=\"selPortionSize$i\" SIZE=\"1\">\n";
echo getPortionSize() . "\n";
echo "</SELECT>\n</TD>\n";
echo "<TD align=\"left\" width=\"33%\"><SELECT NAME=\"selIngredient$i\" SIZE=\"1\">\n";
echo getIngredients() . "\n";
echo"<TD width=\"32%\"><input type=\"text\" name=\"tfInstruction$i\" size=\"30\" maxlength=\"50\">\n</TD>";
echo "</SELECT>\n</TD>\n";
echo "<TD align=\"RIGHT\" width=\"5%\"><input type=\"text\" name=\"tfItemCost$i\" size=\"3\" maxlength=\"5\">\n</td>\n</TR>\n";
}
echo "<TR><TD><input type=\"submit\" name=\"doCost\" value=\"Cost & Add\"></TD><TD><input type=\"Button\" name=\"doCost\" value=\"Cost It\" onclick=\"java script: shiftCost();\"></td><TD><input type=\"Reset\"></TD>";
echo "<TD>Total Cost<input type=\"text\" name=\"tfTotalItemCost\" size=\"5\" maxlength=\"5\"></TD>\n";
echo "<TD>Sell@<input type=\"text\" name=\"tfSellPrice\" size=\"5\" maxlength=\"5\"></TD></TR>";
echo "</TABLE></FORM>";
}
if(isset($doCost) )
{
$dbConn = new MyConnect();
$temp_id = uniqid(id);
$menu_item_id = substr($temp_id,0,11);
echo "<H4>Added items and cost</h4>";
for( $i = 0; $i < floor( sizeof( ${"HTTP_" . $REQUEST_METHOD . "_VARS"} ) / 5 ); $i++ )
$rows[ $i ] = Array( $ingred = explode(":", ${"HTTP_" . $REQUEST_METHOD . "_VARS"}[ "selIngredient" . $i ]),
${"HTTP_" . $REQUEST_METHOD . "_VARS"}[ "selPortionSize" . $i ],
${"HTTP_" . $REQUEST_METHOD . "_VARS"}[ "tfUnit" . $i ],
${"HTTP_" . $REQUEST_METHOD . "_VARS"}[ "tfInstruction" . $i ],
$menu_item_id );
foreach( $rows as $row )
{
$sql = "INSERT INTO recipe( recipe_name, menu_item_id )
[COLOR=red]VALUES('" . $recName . [/color]"', '" . $menu_item_id . "' )";
$rs = mysql_query( $sql, $dbConn->conn ) or die ( mysql_error() );
$sql = "INSERT INTO recipe_ingredient( recipe_ingredient, menu_item_id, ingredient_id )
VALUES( '" .
$row[ 0 ][ 1 ] .
"', '" . $row[ 4 ] .
"', " . $row[ 0 ][ 0 ] .
")";
$rs = mysql_query( $sql ) or die ( mysql_error() );
$sql = "INSERT INTO prep( menu_item_id, instruction ) VALUES('" .
$menu_item_id .
"', '" . $row[ 3 ] . "')";
$rs = mysql_query( $sql ) or die ( mysql_error() );
}
}
?>
</BODY>
</HTML>