Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stumped by $PHP_SELF, possible scope issue?

Status
Not open for further replies.

phpPete

Programmer
Feb 25, 2002
88
US
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

Code:
<?php
include(&quot;../../include/phpClasses/MyConnect.php&quot;);

/*
if( $sessionAccessLevel != 1 )
{
header(&quot;Location: UserOptionsPage.php&quot;);
}
*/
$num = $tfNum;
$recName = $tfRecipeName;



function getIngredients()
{
 $dbConn = new MyConnect();
 $sql = &quot;SELECT DISTINCT ingredient_id, ingredient, gross_cost from ingredient ORDER BY ingredient&quot;;
 $rs = mysql_query($sql, $dbConn->conn)or die(&quot;Connection to DataBase failed&quot;);
    for($i = 0; $i < mysql_num_rows( $rs ); $i++)
     {
      $tmp = mysql_fetch_row( $rs );
      print(&quot;<OPTION value=\&quot;$tmp[0]:$tmp[1]:$tmp[2]\&quot;>$tmp[1]</OPTION>\n&quot;);
     }
}


function getPortionSize()
{
 $dbConn = new MyConnect();
 $sql = &quot;SELECT DISTINCT portion_conversion, portion_type from measurement&quot;;
 $rs = mysql_query($sql, $dbConn->conn)or die(&quot;Connection to DataBase failed&quot;);
    for($i = 0; $i < mysql_num_rows( $rs ); $i++)
     {
      $tmp = mysql_fetch_row( $rs );
      print(&quot;<OPTION value=\&quot;$tmp[0]\&quot;>$tmp[1]</OPTION>\n&quot;);
     }
}
?>
<HTML>
   <HEAD>
      <TITLE>
      </TITLE>
<SCRIPT LANGUAGE=&quot;JavaScript&quot; TYPE=&quot;text/javascript&quot;>

   function shiftCost()// called by event clicking &quot;doCost&quot; 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[&quot;tfUnit&quot; + i].value;
        amount = document.frmAddAndCost.elements[&quot;selPortionSize&quot; + i].value;
        cost = document.frmAddAndCost.elements[&quot;selIngredient&quot; + i].value.split(&quot;:&quot;);                
        netCost = (unit * amount) * cost[2];
        
        document.frmAddAndCost.elements[&quot;tfItemCost&quot; + i].value = netCost;
        
        total += parseFloat(document.frmAddAndCost.elements[&quot;tfItemCost&quot; + i].value);
        sellAt = parseFloat((total/goal)*100);
                
        document.frmAddAndCost.elements[&quot;tfTotalItemCost&quot;].value = Math.round( total * 100 ) / 100;                        
        document.frmAddAndCost.elements[&quot;tfSellPrice&quot;].value = Math.round( sellAt * 100) / 100;        
        }
    }
    
   
</SCRIPT>
   </HEAD>
   <BODY>
      <IMG SRC=&quot;images/msrg.gif&quot; WIDTH=&quot;452&quot; HEIGHT=&quot;48&quot; ALT=&quot;&quot; BORDER=&quot;0&quot;>
      <BR>
      <BR>
      <BR>
      <? echo &quot;<b><center>Recipe Definition for<br><font color=\&quot;red\&quot; size=\&quot;+2\&quot;>$recName</font><br></center></b>&quot;;?>

         <TABLE ALIGN=&quot;center&quot; BGCOLOR=&quot;#f1cb85&quot; CELLPADDING=&quot;2&quot; CELLSPACING=
         &quot;2&quot; WIDTH=&quot;99%&quot;>
            <TR>
               <TD WIDTH=&quot;20%&quot; ALIGN=&quot;left&quot;>
                  <FONT COLOR=&quot;blue&quot; SIZE=&quot;+1&quot;>Amt</FONT>
               </TD>
               <TD WIDTH=&quot;20%&quot; ALIGN=&quot;LEFT&quot;>
                  <FONT COLOR=&quot;blue&quot; SIZE=&quot;+1&quot;>Unit</FONT>
               </TD>
               <TD WIDTH=&quot;20%&quot; ALIGN=&quot;LEFT&quot;>
                  <FONT COLOR=&quot;blue&quot; SIZE=&quot;+1&quot;>Ingredient</FONT>
               </TD>
               <TD WIDTH=&quot;20%&quot; ALIGN=&quot;RIGHT&quot;>
                  <FONT COLOR=&quot;blue&quot; SIZE=&quot;+1&quot;>Description</FONT>
               </TD>
               <TD WIDTH=&quot;20%&quot; ALIGN=&quot;right&quot;>
                  <FONT COLOR=&quot;blue&quot; SIZE=&quot;+1&quot;>Cost</FONT>
               </TD>
            </TR>
         </TABLE>
         <TABLE ALIGN=&quot;center&quot; id=&quot;costTable&quot; WIDTH=&quot;90%&quot;>
         
            <?php 
            
        if( $tfNum <= 0 )
            {
            echo &quot;<br><br>&quot;;
            echo &quot;<form action=\&quot;$PHP_SELF\&quot; method=\&quot;post\&quot; name=\&quot;frmSetIngredientLength\&quot; id=\&quot;frmSetIngredientLength\&quot;>&quot;;
            echo &quot;<br>Recipe Name:<input type=\&quot;text\&quot; name=\&quot;tfRecipeName\&quot; id=\&quot;tfRecipeName\&quot; size=\&quot;50\&quot; maxlength=\&quot;50\&quot;>
            echo &quot;<BR>Number of ingredients for this recipe:<input type=&quot;text\&quot; name=\&quot;tfNum\&quot; size=\&quot;2\&quot; maxlength=\&quot;2\&quot; value=\&quot;$num\&quot;>&quot;;
            echo &quot;<br><input  type=\&quot;submit\&quot; name=\&quot;buildForm\&quot; value=\&quot;Build Form\&quot;>&quot;;
            echo &quot;</FORM>&quot;;
            }
        
        elseif(isset($buildForm))
            {
                echo &quot;<FORM ACTION=\&quot;$PHP_SELF\&quot; METHOD=\&quot;post\&quot; NAME=\&quot;frmAddAndCost\&quot;>\n\n&quot;;
                for( $i = 0; $i < $num; $i++)
                 {
                 echo &quot;<TR>\n<TD ALIGN=\&quot;left\&quot; WIDTH=\&quot;5%\&quot;><input type=\&quot;text\&quot; name=\&quot;tfUnit$i\&quot; size=\&quot;5\&quot; maxlength=\&quot;5\&quot;>\n</td>\n&quot;;
                 echo &quot;<TD ALIGN=\&quot;justify\&quot; WIDTH=\&quot;5%\&quot;>\n<SELECT NAME=\&quot;selPortionSize$i\&quot; SIZE=\&quot;1\&quot;>\n&quot;;
                 echo getPortionSize() . &quot;\n&quot;;
                 echo &quot;</SELECT>\n</TD>\n&quot;;
                 echo &quot;<TD align=\&quot;left\&quot; width=\&quot;33%\&quot;><SELECT NAME=\&quot;selIngredient$i\&quot; SIZE=\&quot;1\&quot;>\n&quot;;
                 echo getIngredients() . &quot;\n&quot;;
                 echo&quot;<TD width=\&quot;32%\&quot;><input type=\&quot;text\&quot; name=\&quot;tfInstruction$i\&quot; size=\&quot;30\&quot; maxlength=\&quot;50\&quot;>\n</TD>&quot;;
                 echo &quot;</SELECT>\n</TD>\n&quot;;
                 echo &quot;<TD align=\&quot;RIGHT\&quot; width=\&quot;5%\&quot;><input type=\&quot;text\&quot; name=\&quot;tfItemCost$i\&quot; size=\&quot;3\&quot; maxlength=\&quot;5\&quot;>\n</td>\n</TR>\n&quot;;
                 }
                echo &quot;<TR><TD><input type=\&quot;submit\&quot; name=\&quot;doCost\&quot; value=\&quot;Cost & Add\&quot;></TD><TD><input type=\&quot;Button\&quot; name=\&quot;doCost\&quot; value=\&quot;Cost It\&quot; onclick=\&quot;java script: shiftCost();\&quot;></td><TD><input type=\&quot;Reset\&quot;></TD>&quot;;
                echo &quot;<TD>Total Cost<input type=\&quot;text\&quot; name=\&quot;tfTotalItemCost\&quot; size=\&quot;5\&quot; maxlength=\&quot;5\&quot;></TD>\n&quot;;
                echo &quot;<TD>Sell@<input type=\&quot;text\&quot; name=\&quot;tfSellPrice\&quot; size=\&quot;5\&quot; maxlength=\&quot;5\&quot;></TD></TR>&quot;;
                echo &quot;</TABLE></FORM>&quot;;
                
            }
if(isset($doCost) )
    {
        
        $dbConn = new MyConnect();
        $temp_id = uniqid(id);
          $menu_item_id = substr($temp_id,0,11);
        echo &quot;<H4>Added items and cost</h4>&quot;;
        for( $i = 0; $i < floor( sizeof( ${&quot;HTTP_&quot; . $REQUEST_METHOD . &quot;_VARS&quot;} ) / 5 ); $i++ )
        $rows[ $i ] = Array( $ingred = explode(&quot;:&quot;, ${&quot;HTTP_&quot; . $REQUEST_METHOD . &quot;_VARS&quot;}[ &quot;selIngredient&quot; . $i ]),
        ${&quot;HTTP_&quot; . $REQUEST_METHOD . &quot;_VARS&quot;}[ &quot;selPortionSize&quot; .  $i ],
        ${&quot;HTTP_&quot; . $REQUEST_METHOD . &quot;_VARS&quot;}[ &quot;tfUnit&quot; . $i ],
        ${&quot;HTTP_&quot; . $REQUEST_METHOD . &quot;_VARS&quot;}[ &quot;tfInstruction&quot; . $i ],
        $menu_item_id );

foreach( $rows as $row )
        {
            $sql = &quot;INSERT INTO recipe( recipe_name, menu_item_id )
                 [COLOR=red]VALUES('&quot; . $recName . [/color]&quot;', '&quot; . $menu_item_id . &quot;' )&quot;;
            $rs = mysql_query( $sql, $dbConn->conn ) or die ( mysql_error() );
            
            $sql = &quot;INSERT INTO recipe_ingredient( recipe_ingredient, menu_item_id, ingredient_id )
                    VALUES( '&quot; . 
                    $row[ 0 ][ 1 ] . 
                    &quot;', '&quot; . $row[ 4 ] . 
                    &quot;', &quot; . $row[ 0 ][ 0 ] . 
                    &quot;)&quot;;
            $rs = mysql_query( $sql ) or die ( mysql_error() );
            
            $sql = &quot;INSERT INTO prep( menu_item_id, instruction ) VALUES('&quot; . 
            $menu_item_id .
            &quot;', '&quot; . $row[ 3 ] . &quot;')&quot;;
            $rs = mysql_query( $sql ) or die ( mysql_error() );
        } 


}
?>
            
   </BODY>
</HTML>
 
Problem solved. Used a hidden field, which I was hoping not to have to use but c'est la vie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top