?
Solved

Help with multiplying Qty

Posted on 2005-03-10
22
Medium Priority
?
549 Views
Last Modified: 2008-02-26
I have a form that has checkboxes created by an array(the value is an item in my database), I need to add a quantity field next to the checkbox and then have the checkbox multiplied by the quantity the user inputs.  I really have no idea how to go about doing this,  I've tried this code below but I do not know how to assign the text input to the corresponding checkbox.  

while ($row = mysql_fetch_array($result1, MYSQL_ASSOC))
{
      $field1= "$row[EClass]$row[Round]";
      $field2= $row["Fee"];
      $field3= $row["EClass"];
echo("       
<tr>
   <td bgcolor='#E3EAF4'><center><input type=\"checkbox\" name=\"name[]\" value=\"$field1\"></td>
   <td bgcolor='#E3EAF4'><center>$field3</td>
   <td bgcolor='#E3EAF4'><center>$field2</td>
   <td bgcolor='#E3EAF4'><center><input type=\"text\" name=\"qty[]\" value=\"0\"  size=\"2\" maxlength=\"2\"\"></td>
</tr>");
}


After the form is submitted I save the information into and object, this is the code I use to save checkboxes but do not know how to save the value of the checkbox X Qty.

for($i=0;$i<sizeof($frm['name']);$i++)$order->checkbox[]=$frm['name'][$i]             

Any help is appreciated.
0
Comment
Question by:asmaynard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 8
22 Comments
 
LVL 17

Expert Comment

by:davebytes
ID: 13514083
Ummm... should just be in $frm['qty'][$i], if I'm reading your code correctly.  Also your code is confusing, as it doesn't seem to eliminate unchecked stuff (which most such scripts would).  But something like:

for($i=0;$i<sizeof($frm['name']);$i++)
{
  $order->checkbox[] = ($frm['name'][$i] ? $frm['qty'][$i] : 0);
}

... might work.  Depends on what value you want in checkbox[]... you could change the 0 to 'false' to make it more explicit, or not even assign a checkbox[] entry if 'name' field is 0/false to start with...

-d
0
 
LVL 7

Expert Comment

by:aib_42
ID: 13514484
Try:

foreach($frm['name'] as $id => $field1) {

  $order->quantity[] = (int) (isset($frm['qty'][$id]) ? $frm['qty'][$id] : X); /* Don't type X, place either 0 or 1 there */

}

This will give you an array, similar to $order->checkbox[], that will have the value of the qty field *for every item selected*. If the field is empty, it will have value 'X', which should be replaced by either 0 or 1 depending on how you want to handle empty quantity fields.

Or, you could modify your existing loop:

for($i=0;$i<sizeof($frm['name']);$i++) {

  $order->checkbox[]=$frm['name'][$i];
  $order->quantity[]=$frm['qty'][$i];

}
0
 

Author Comment

by:asmaynard
ID: 13514552
I apologize for this being confusing, I'm new to PHP.  What I'm trying to do with this form is have a 2 section checkout page where the first section a user can select from a list of single items by using a checkbox only and in the second section choose from multiple items by selecting a checkbox and inputting a quantity amount.  I've been successful at getting the single checkboxes to work by using this code:

        <input type=\"checkbox\" name=\"name[]\" value=\"$field1\">

in a loop on the form page.  On page submission the data the user inputs is then saved as an object with this code:

        for($i=0;$i<sizeof($frm['name']);$i++)$order->checkbox[]=$frm['name'][$i];              

and then the user is taken to a confirmation page where the order info is loaded using this code:

        for($i=0;$i<sizeof($info->checkbox);$i++)$checkbox[]=$info->checkbox[$i];

and then defined as a variable with this code:

for($no=0;$no<count($checkbox);$no++){
  $result=mysql_query("SELECT wClassesDet.Fee, wClassesDet.EClass FROM wClassesDet, wClasses WHERE       wClasses.Event = '$prod->Event' and ClassRnd = '$checkbox[$no]' and wClasses.ProducerID=
      '$prod->ProducerID' and wClasses.Association = '$prod->Association'");
if(!$result)
{
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
}
    if($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
     $product_fee=$row["Fee"];
     $round_name=$row["EClass"];
     
     echo "$product_fee<br>";
}      
}

The value of each checkbox is equal to an item's name in my database so when I calculate $product_fee the SQL query selects the item's fee where the item's name equaled '$checkbox[$no]'.  I want the checkbox/Qty section to do exactly the same as above with the exception of $product_fee to be multiplied by the quantity the user inputs and echo the results as this:

echo "$product_fee x $qty = $total"

I figure that the checkbox/Qty section on my form should name the checkbox array something different than "name[]" as it is named in the checkbox only section.  I've messed around with your code in conjunction with the code in my first post on how I create the checkbox/Qty input, but I think the value of the checkbox is being altered so when I try to run the SQL query no results are returned.  I think that giving the text input a value of '0' is causing this, I need the checkbox/Qty section to maintain a value of $field1(the items name) so when I run the SQL query I'm able to return the product's fee and then multiply it by quantity.   I'm guessing that I've been going at this all wrong.

I hope this explanation is not to confusing to understand and helps explain what I'm trying to accomplish.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 17

Expert Comment

by:davebytes
ID: 13519063
That's much more information! ;)

I'd personally do something like this:

// store the data:
foreach ($frm['name'] as $index => $productname)
{
  $order->checkbox[]['name'] = $productname;
  $order->checkbox[]['qty'] = (empty($frm['qty']) ? 0 : intval($frm['qty']));
}
// that will store all the data off of ONE array, using subfields.

// confirmation page:
$checkbox = array();
foreach($info->checkbox as $index => $product)
  $checkbox[] = $product; // simple now!

// then your output code:
for($no=0;$no<count($checkbox);$no++)
{
  $result=mysql_query("SELECT wClassesDet.Fee, wClassesDet.EClass FROM wClassesDet, wClasses WHERE      wClasses.Event = '$prod->Event' and ClassRnd = '".$checkbox[$no]['name']."' and wClasses.ProducerID='$prod->ProducerID' and wClasses.Association = '$prod->Association'");
  if(!$result)
  {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
  }
  if($row=mysql_fetch_array($result, MYSQL_ASSOC))
  {
     $product_fee=$row["Fee"];
     $round_name=$row["EClass"];
     
     $totalfee = $checkbox[$no]['qty'] * $product_fee;
     echo $checkbox[$no]['name'].": ";
     echo $checkbox[$no]['qty']. " x $product_fee = $totalfee<br/>";
  }
  else
  {
    // HANDLE THIS...
  }    
}

----------------
obviously, can't test this myself... ;)

hope that helps,
-d
0
 

Author Comment

by:asmaynard
ID: 13520071
Dave,
Thanks for the help, but I'm still not receiving the right results.  No Qty is returned at all and the fee is wrong.  I know it is hard for you to help without me posting all my code, but I will post the checkbox/qty creation code and the entire functions and see if that can help.

The checkbox is created like this(page 1):


$result1 = mysql_query( "SELECT wClassesDet.EClass, wClassesDet.Fee, Round FROM wClassesDet,
      wClasses WHERE wClasses.Event = '$prod->Event' and wClasses.ProducerID=
      '$prod->ProducerID' and wClasses.Association = '$prod->Association' and
      wClassesDet.EClass = wClasses.EClass and wClasses.Event = wClassesDet.Event and
      wClasses.Race = 0" ) or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result1);
if (!$result1)
{
      echo("<p>Error performing query: " . mysql_error() . "</p>");
      exit();
}
  if ($num_rows >=1)
{      
    while ($row = mysql_fetch_array($result1, MYSQL_ASSOC))
{
      $field1= "$row[EClass]$row[Round]";
      $field2= $row["Fee"];
      $field3= $row["EClass"];
echo("       
      <tr>
      <td></td>
      <td bgcolor='#E3EAF4'><center><input type=\"checkbox\" name=\"fee[]\" value=\"$field1\"></td>
      <td bgcolor='#E3EAF4'><center>$field3</td>
      <td bgcolor='#E3EAF4'><center>$field2</td>
      <td bgcolor='#E3EAF4'><center><input type=\"text\" name=\"qty[]\" size=\"2\" maxlength=\"2\"\"></td>
      </tr>");
}
}


I've changed the name of the checkbox to "fee[]" instead of "name[]" as to not conflict with the single checkboxes in the first section of my form and also dropped the value of the qty input to not conflict with the checkbox value.

The page is submitted and saved with this function:


function save_orderinfo(&$frm) {
/* this function saves the order information into the session variable
 * $SESSION["orderinfo"].  it is used in the purchase confirmation stage */

      global $USER;

      $order = new Object();
      
if (isset($_POST['child_name']))  
       {$order->customer = $frm["child_name"];}
 if (empty($_POST['child_name']))
      {$order->customer = $USER["user"]["firstname"] . " " . $USER["user"]["lastname"];}
      $order->contact = $USER["user"]["phone"];
      $order->address = $USER["user"]["address"];
      $order->city = $USER["user"]["city"];
      $order->state = $USER["user"]["state"];            
      $order->zip = $USER["user"]["zip"];
      $order->horse = $frm["horse"];
      $order->child_name = $frm["child_name"];
for($i=0;$i<sizeof($frm['name']);$i++)$order->checkbox[]=$frm['name'][$i];            
foreach ($frm['fee'] as $index => $productname)
{
  $order->checkbox_1[]['fee'] = $productname;
  $order->checkbox_1[]['qty'] = (empty($frm['qty']) ? 0 : intval($frm['qty']));
}
            
      $USER["orderinfo"] = &$order;
}


You can see where I've added your code to the end of the function.  Once the order is saved as an object, the page is redirected to my confirmation page where the order is loaded with this(page 2):

 
if ($info = load_orderinfo()) {
      $custid = $USER["user"]["custid"];
      $customer = $info->customer;
      $contact = $info->contact;
      $address = $info->address;
      $city = $info->city;
      $state = $info->state;
      $zip = $info->zip;
      $horse = $info->horse;
      $event = $prod->Event;
for($i=0;$i<sizeof($info->checkbox);$i++)$checkbox[]=$info->checkbox[$i];
$checkbox_1 = array();
foreach($info->checkbox_1 as $index => $product)
  $checkbox_1[] = $product; // simple now!
}


I then have each part of the order echoed, which all works right except for the checkbox/qty.  I recieve an undefined index name and qty error using the output code you provided.  Thank you very much for your help, hopefully this will be easy to figure out.
0
 
LVL 17

Expert Comment

by:davebytes
ID: 13520843
Trying blindly... ;)  Suggestion, you might want to use a more descriptive field like 'option' instead of 'fee'.  But you can change that at any time.

I definitely posted some bad code -- wasn't grabbing the indexed quantity properly.

To explain my other changes below:
- I got rid of the old 'checkbox[]' array setup.  Changed 'checkbox_1[]' to 'checkbox'.  Only one set needed...
- I changed $product to $option, so the code reads a bit clearer.

Try it out.

-d
--------------------------------

function save_orderinfo(&$frm) {
/* this function saves the order information into the session variable
 * $SESSION["orderinfo"].  it is used in the purchase confirmation stage */

     global $USER;

     $order = new Object();
     
if (isset($_POST['child_name']))  
      {$order->customer = $frm["child_name"];}
 if (empty($_POST['child_name']))
     {$order->customer = $USER["user"]["firstname"] . " " . $USER["user"]["lastname"];}
     $order->contact = $USER["user"]["phone"];
     $order->address = $USER["user"]["address"];
     $order->city = $USER["user"]["city"];
     $order->state = $USER["user"]["state"];          
     $order->zip = $USER["user"]["zip"];
     $order->horse = $frm["horse"];
     $order->child_name = $frm["child_name"];
     // removed old checkbox[], renamed below to be that array instead of checkbox_1[] -- too confusing.
     foreach ($frm['fee'] as $index => $productname)
     {
       $order->checkbox[]['fee'] = $productname;
       $order->checkbox[]['qty'] = (empty($frm['qty'][$index]) ? 0 : intval($frm['qty'][$index]));
     }
         
     $USER["orderinfo"] = &$order;
}

----------------------------------------------------

// again, get rid of old checkbox field, turn checkbox_1 into checkbox...

 
if ($info = load_orderinfo()) {
     $custid = $USER["user"]["custid"];
     $customer = $info->customer;
     $contact = $info->contact;
     $address = $info->address;
     $city = $info->city;
     $state = $info->state;
     $zip = $info->zip;
     $horse = $info->horse;
     $event = $prod->Event;
     $checkbox = array(); // this is to ensure it starts off clean...
     foreach($info->checkbox as $index => $option)
       $checkbox[] = $option; // simple now!
}
0
 

Author Comment

by:asmaynard
ID: 13521102
I named the checkboxes "checkbox_1" due to the first section of the page where the user can only select a checkbox and no quantity the checkboxes are name "checkbox" and figured they need to be different as they will be calcualted differently.  This code is still not returning the item's name but is returning a fee of $7.00(there is not a fee of $7.00 dollars in my database at all), the echo is outputting:

: x 7.00 = 0
: 0 x 7.00 = 0

and I'm still getting undefined indexes "name" and "qty".  The only other thing I can think of doing now is to post the entire pages so you can see how the rest of the code works in relation to what I'm trying to accomplish, but do not know if you'd be willing to sift through all the pages.  Let me know,
Thanks,
Andrew
0
 
LVL 17

Expert Comment

by:davebytes
ID: 13522105
ummm.. well, the product_fee thing is all yours!  that's coming from your data.

as for the naming, totally understood.  didn't know there was a secondary form.

if you are getting undefined index 'name', you have bad code, as I thought you changed all references to 'name' to be 'fee' instead?

And undefined index for 'qty' doesn't make sense.  Maybe it is how you are putting stuff in the database?  Are you escaping things or otherwise encoding things safely for sql?

You should temporarily have you second page (that 'receives' the form data) IMMEDIATELY dump (print_r) the frm variable out and die(), so that you can see that the data is what you expect it to be.  If that all looks correct, do a dump/die just before pulling data from the database to calculate fees.

Otherwise, I'd really need to see this running, possibly get it running here, in order to debug further.  Multi-page things, plus database, completely blind is just too difficult, too many things could be going wrong.  Happy to help, though this is already becoming more time consuming than a 125 pt Q... ;) ;)

-d
0
 

Author Comment

by:asmaynard
ID: 13522858
Dave,
Thanks for all your help, I will gladly increase the value of this question, I didn't realize how much a pain this was going to be.  I'll post each page as its own post so to keep confusing between each page down.

This is my first page which calls the form(purchase_now.php), not much going on here except for calling the template.

<?
include("../application.php");
$prod = load_product($_REQUEST["event"]);
$id = nvl($_REQUEST["event"], 1);
$qid_p = get_event();
$DOC_TITLE = "Shopping Catalog";
$template_to_show = "templates/purchase_now.php";


/* form has been submitted */
if (match_referer() && isset($_POST)) {
      $frm = $_POST;
      $errormsg = validate_form($frm, $errors);

      if (empty($errormsg)) {
            save_orderinfo($_POST);

            $DOC_TITLE = "MyMarket Purchase Confirmation";
redirect ("http://www.payraces.com/shopping/purchase_confirm.php?event=$prod->Event&prodid=$prod->ProducerID&assoc=$prod->Association");
      }

}

$frm = $_REQUEST;
include("$CFG->templatedir/header.php");
include("$CFG->templatedir/form_header.php");
include($template_to_show);
include("$CFG->templatedir/footer.php");

/******************************************************************************
 * FUNCTIONS
 *****************************************************************************/
function validate_form(&$frm, &$errors) {
/* validate the forgot password form, and return the error messages in a string.
 * if the string is empty, then there are no errors */

      global $USER;

      $errors = new Object;
      $msg = "";

      if  (empty($frm["horse"])) {
            $errors->horse = true;
            $msg .= "<li>You did not specify a horse";
}
      return $msg;
}


function require_login1() {
/* this function checks to see if the user is logged in.  if not, it will show
 * the login screen before allowing the user to continue */

      global $CFG, $USER, $prod;

      if (! is_logged_in()) {
            $USER["wantsurl"] = qualified_me();
            redirect("http://www.payraces.com/shopping/login.php?event=$prod->Event");
      }
}


?>
0
 

Author Comment

by:asmaynard
ID: 13522872
This is the template called in page 1(purchase_now.php).  I know it's incredibly long, I'm working to condense the code in to a more elegant form, but this is only my second month working with PHP so I'm still learning.  The section containing the Checkbox and Qty is at the very end of the code and is remarked by:

/*------------------------------------------------------------------------
Other Event Fees(section with chechbox & Qty)
-------------------------------------------------------------------------*/


<html>
<table width="768" border="0">
  <tr>
    <th width="762" scope="col"><span class="style10"><u>Registration for
          <? pv($prod->EName)?>
    </u></span></th>
  </tr>
</table>
<form name="entryform" action="<?="$ME?event=$prod->Event&prodid=$prod->ProducerID&assoc=$prod->Association"?>" method="post">
<table width="768" border="0">
  <tr>
    <th width="762" scope="col"><span class="style13 style12">Please Enter Information for Producer</span></th>
  </tr>
</table><br>

<table width="768" border="1" bordercolor="#000000" bgcolor="#AEAEFF">
      <tr>
            <th width="8" bordercolor="#AEAEFF" scope="col">&nbsp;
            </th>
            <th width="198" align="left" valign="top" bordercolor="#AEAEFF" scope="col"><div align="left"><span class="style16">
                    <u>Personal Information</u></span></div>
            </th>
            <td width="540" bordercolor="#AEAEFF"><div align="right"><span class="style16 style15"><strong>
            <a href="<?=$CFG->wwwroot?>/shopping/change_personal_1.php?event=<?=$prod->Event?>&prodid=<?=$prod->ProducerID?>&assoc=<?=$prod->Association?>">
              change personal information</a></strong></span></div>
            </td>
    </tr>
</table>

<table>
      <tr>
            <td width=214></td>
            <td width="63" class=label>Name:</td>
            <td width="331"><FONT face=arial size=2><? pv($customer) ?></td>
      </tr>
      <tr valign=top>
            <td></td>
            <td class=label>Phone:</td>
            <td><FONT face=arial size=2><? pv($contact) ?></td>
      </tr>
      <tr valign=top>
            <td></td>
            <td class=label>Address:</td>
            <td><FONT face=arial size=2><? pv($address) ?></td>
      </tr>
      <tr>
            <td></td>
            <td class=label>&nbsp;</td>
            <td><FONT face=arial size=2><? pv($city) ?>, <? pv($state) ?> <? pv($zip) ?></td>
      </tr>
      <tr>
            <td></td>
            <td class=label>Email:</td>
            <td><FONT face=arial size=2><? pv($email) ?></td>
      </tr>
</table>
 
<table width="621">
      <tr>
            <td width="213"></td>
            <td width="63" valign="top" class=label>Bio:</td>
            <td width="329"><FONT face=arial size=2><? pv($bio) ?></td>
    </tr>
</table>

<br>

<table width="768" border="1" bordercolor="#000000" bgcolor="#AEAEFF">
      <tr>
            <th width="8" bordercolor="#AEAEFF" scope="col">&nbsp;</th>
            <th width="238" align="left" valign="top" bordercolor="#AEAEFF" scope="col"><div align="left"><span class="style16">
                  <u>Horse &amp; Child Information</u></span></div></th>
            <td width="500" bordercolor="#AEAEFF"><div align="right"></div></td>
    </tr>
</table>

<br>

<table width="738" border="0">
      <tr>
            <th width="196" height="21" scope="col"><div align="right"><span class="style16"><u>Select Horse </u></span></div></th>
            <th width="97" scope="col"><div align="center"><span class="style15 style16">
                  <a href="<?=$CFG->wwwroot?>/users/horses.php?event=<?=$prod->Event?>&prodid=<?=$prod->ProducerID?>&assoc=<?=$prod->Association?>">
                  add horse </a></span></div></th>
            <th width="351" scope="col"><div align="right"><span class="style16"><u>Select Child</u><span class="style17"> (if applicable)
                  </span></span></div></th>
            <th width="107" scope="col"><div align="center"><span class="style15 style16">
                  <a href="<?=$CFG->wwwroot?>/users/child_1.php?event=<?=$prod->Event?>&prodid=<?=$prod->ProducerID?>&assoc=<?=$prod->Association?>">
                  add child </a></span></div></th>
    </tr>
</table>

<table width="738" border="0">
      <tr>
            <th width="355" height="21" scope="col"><div align="center"><span class="style16">
                  <?
                  // Horse drop down menu
                  $sql="SELECT horse FROM wHorses WHERE custid = '$custid'";
                  $result=mysql_query($sql);
                  $options="";

                  while ($row=mysql_fetch_array($result))
                  {
                        $id=$row["horse"];
                        $title=$row["horse"];
                        $options.="<OPTION VALUE=\"$id\">".$title;
                  }
                  ?>
                  <select name="horse" id="horse">
                  <option value=0>Select Horse
                  <?=$options?>
                  </select>
                  <?err($errors->horse)?>
                  </span></div>
                  <?
                  // End Horse drop down
                  ?>
            </th>
            <th width="34" scope="col">&nbsp;</th>
            <th width="335" scope="col"><div align="center"><span class="style15 style16">
                  <?
                  // Child drop down
                  $sql="SELECT RName FROM wChildren WHERE custid = '$custid'";
                  $result=mysql_query($sql);
                  $options="";

                  while ($row=mysql_fetch_array($result))
                  {
                      $id=$row["RName"];
                        $title=$row["RName"];
                        $options.="<OPTION VALUE=\"$id\">".$title;
                  }
                  ?>
                  <select name="child_name" id="child_name">
                  <option value=0>Select Child
                  <?=$options?>
                  </select>
                  </span></div>
                  <?
                  // End Child drop down
                  ?>
            </th>
      </tr>
</table>

<br>

<table width="768" border="1" bordercolor="#000000" bgcolor="#AEAEFF">
      <tr>
            <th width="8" bordercolor="#AEAEFF" scope="col">&nbsp;</th>
            <th width="238" align="left" valign="top" bordercolor="#AEAEFF" scope="col"><div align="left"><span class="style16">
                  <u>Race Information</u></span></div></th>
            <td width="500" bordercolor="#AEAEFF"><div align="right"></div></td>
      </tr>
</table>

<br>

<table width="742" border="0">
      <tr>
            <th scope="col">
             
             
<?php
$result =  mysql_query("SELECT wEvents.Event, wClasses.EClass, wClasses.Fee, wClasses.Comments, wClasses.UseFee FROM wEvents, wClasses
                                    WHERE wEvents.Event = '$prod->Event' and wEvents.ProducerID= '$prod->ProducerID' and wEvents.Association =
                                    '$prod->Association' and wClasses.Event = wEvents.Event and wClasses.Race >= 1 ORDER by EOrder");
if (!$result)
      {
            echo("<p>Error performing query: " . mysql_error() . "</p>");
            exit();
      }

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

/*----------------------------------------------------------------------------------------
UseFee is True; Fee is printed next to class; Checkbox is next to class;
-----------------------------------------------------------------------------------------*/

$result1=  mysql_query("SELECT DISTINCT wClassesDet.Round FROM wClassesDet, wClasses WHERE wClassesDet.Event = '$prod->Event' and
                                    wClassesDet.ProducerID= '$prod->ProducerID' and wClassesDet.Association = '$prod->Association'
                                    and wClasses.Event = wClassesDet.Event and wClasses.Race >= 1 ORDER by EOrder");

if (!$result1)
      {
            echo("<p>Error performing query: " . mysql_error() . "</p>");
            exit();
      }

                        
while ($row_1 = mysql_fetch_array($result1, MYSQL_ASSOC)) {                                     

      $field1= "$row[EClass]$row_1[Round]";
      if ($row["UseFee"] >=1 )
      {
              echo("
            <table width=\"650\" border=\"0\">
                  <tr>
                      <th width=\"200\"><div align=\"left\"><FONT face=arial size=3> " . $row["EClass"] . " : $" . $row["Fee"] . " 
                        <input type=\"checkbox\" name=\"name[]\" value=\"$field1\"> " . $row["Comments"] . " </i></U></div></th>
                    </tr>
            </table>");
            
      $result4 = mysql_query("SELECT Round, RName, wClassesDet.Fee, NoPay, EOrder, wClassesDet.EClass FROM wClassesDet, wClasses
                                          WHERE wClasses.Event = '$prod->Event' and wClassesDet.EClass = wClasses.EClass and wClassesDet.ProducerID
                                          = '$prod->ProducerID' and wClassesDet.Association = '$prod->Association' and wClasses.Event =
                                          wClassesDet.Event and wClassesDet.EClass = '$row[EClass]' and wClasses.Race >= 1 ORDER BY EOrder");
      if (!$result4)
      {
            echo("<p>Error performing query: " . mysql_error() . "</p>");
            exit();
      }
      while ($row = mysql_fetch_array($result4, MYSQL_ASSOC))
      {
            $field1= "$row[EClass]$row[Round]";
            $field2= $row["Fee"];
            $field3= $row["Round"];
            $field4= $row["RName"];
            $field5= $row["Fee"];
            $field6= $row["NoPay"];
      print "<table width=440 border=0>\n";
      print "<tr><td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;Round&nbsp; </td>\n";
      print "<td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;&nbsp;&nbsp;Name&nbsp; </td>\n";
      print "<td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;&nbsp;&nbsp;Fee&nbsp;&nbsp;&nbsp;&nbsp; </td>\n";
      print "<td><FONT face=tahoma size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>\n";
                  echo("       
                  <tr>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field3</td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field4</td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field5</td>
                  <td width=\"15\"></td>
                  </tr>");
                        
            }
      }
/*-------------------------------------------------------------------------------
IF Fee = 0.00(no value) Section; does not show Fee; Checkbox next to Round
-------------------------------------------------------------------------------*/
      elseif ($row["Fee"] == '0.00')
      {
            echo("
            <table width=\"650\" border=\"0\">
                  <tr>
                        <th width=\"200\"><div align=\"left\"><FONT face=arial size=3> " . $row["EClass"] . " : " . $row["Comments"] . "</i>
                        </U></div></th>
                    </tr>
            </table>");
$result1 = mysql_query( "SELECT Round, RName, wClassesDet.Fee FROM wClassesDet, wClasses WHERE wClasses.Event = '$prod->Event'
                                    and wClassesDet.EClass = wClasses.EClass and wClasses.Event = wClassesDet.Event and wClassesDet.EClass =
                                    '$row[EClass]' and wClasses.Race >= 1 ORDER BY `EOrder` " ) or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result1);
      print "<table width=440 border=0>\n";
      print "<td bgcolor='cccccc'><FONT face=tahoma size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\n";
      print "<td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;Round&nbsp; </td>\n";
      print "<td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;&nbsp;&nbsp;Name&nbsp; </td>\n";
      print "<td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;&nbsp;&nbsp;Fee&nbsp;&nbsp;&nbsp;&nbsp; </td>\n";
while ($get_info = mysql_fetch_row($result1)){
      print "<tr>\n";
      $result4 = mysql_query("SELECT Round, RName, wClassesDet.Fee, NoPay, EOrder, wClassesDet.EClass FROM wClassesDet, wClasses
                                          WHERE wClasses.Event = '$prod->Event' and wClassesDet.EClass = wClasses.EClass and wClassesDet.ProducerID
                                          = '$prod->ProducerID' and wClassesDet.Association = '$prod->Association' and wClasses.Event =
                                          wClassesDet.Event and wClassesDet.EClass = '$row[EClass]' and wClasses.Race >= 1 ORDER BY EOrder");
      if (!$result4)
      {
            echo("<p>Error performing query: " . mysql_error() . "</p>");
            exit();
      }
      while ($row = mysql_fetch_array($result4, MYSQL_ASSOC))
      {
            $field1= "$row[EClass]$row[Round]";
            $field2= $row["Fee"];
            $field3= $row["Round"];
            $field4= $row["RName"];
            $field5= $row["Fee"];
            $field6= $row["NoPay"];
            if ($field6 >= 1)
            {
                  echo("       
                  <td width=\"20\" bgcolor='#E3EAF4'></td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field3</td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field4</td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field5</td>
                  </tr>");
            }
            else
            {
                  echo("       
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center><input type=\"checkbox\" name=\"name[]\" value=\"$field1\"></td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field3</td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field4</td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field5</td>
                  </tr>");
            }
      ;}
$result1 = mysql_query( "SELECT Round, RName, wClassesDet.Fee FROM wClassesDet, wClasses WHERE wClasses.Event = '$prod->Event'
                                    and wClassesDet.EClass = wClasses.EClass and wClasses.Event = wClassesDet.Event and wClassesDet.EClass =
                                    '$row[EClass]' and NoPay < 1 and wClasses.Race >= 1 ORDER BY `Round`") or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result1);
      while ($get_info = mysql_fetch_row($result1))
      {
            print "<tr>\n";
            print "<td></td>";
            print "<td></td>";
            foreach ($get_info as $field)
            print "\t<td><font face=arial size=2/><div align=\"center\">$field</div></font></td>\n";
            print "</tr>\n";
      }
      }
      print "</table><br>\n";            
      }
/*--------------------------------------------------------------------------
UseFee = False; Fee > $0.00;
---------------------------------------------------------------------------*/      
      else
      {
            echo("
            <table width=\"650\" border=\"0\">
                  <tr>
                      <th width=\"20\">&nbsp;</th>
                        <th width=\"200\"><div align=\"left\"><FONT face=arial size=3> " . $row["EClass"] . ": " . $row["Comments"] . "</i></U>
                        </div></th>
                    </tr>
            </table>");
$result1 = mysql_query( "SELECT Round, RName, wClassesDet.Fee FROM wClassesDet, wClasses WHERE wClasses.Event = '$prod->Event'
                                    and wClassesDet.EClass = wClasses.EClass and wClasses.Event = wClassesDet.Event and wClassesDet.EClass =
                                    '$row[EClass]' and wClasses.Race >= 1 ORDER BY `EOrder` " ) or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result1);
      print "<table width=440 border=0>\n";
      print "<td width=\"30\" bgcolor='cccccc'><FONT face=tahoma size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\n";
      print "<td width=\"70\" bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;Round&nbsp; </td>\n";
      print "<td width=\"250\" bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;&nbsp;&nbsp;Name&nbsp; </td>\n";
      print "<td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;&nbsp;&nbsp;Fee&nbsp;&nbsp;&nbsp;&nbsp; </td>\n";
while ($get_info = mysql_fetch_row($result1)){
      print "<tr>\n";
      $result4 = mysql_query("SELECT Round, RName, wClassesDet.Fee, NoPay, EOrder, wClassesDet.EClass FROM wClassesDet, wClasses
                                          WHERE wClasses.Event = '$prod->Event' and wClassesDet.EClass = wClasses.EClass and wClassesDet.ProducerID
                                          = '$prod->ProducerID' and wClassesDet.Association = '$prod->Association' and wClasses.Event =
                                          wClassesDet.Event and wClassesDet.EClass = '$row[EClass]' and wClasses.Race >= 1 ORDER BY EOrder");
      if (!$result4)
      {
            echo("<p>Error performing query: " . mysql_error() . "</p>");
            exit();
      }
      while ($row = mysql_fetch_array($result4, MYSQL_ASSOC))
      {
            $field1= "$row[EClass]$row[Round]";
            $field2= $row["Fee"];
            $field3= $row["Round"];
            $field4= $row["RName"];
            $field5= $row["Fee"];
            $field6= $row["NoPay"];
            if ($field6 >= 1)
            {
                  echo("       
                  <td bgcolor='#E3EAF4'></td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field3</td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field4</td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field5</td>
                  </tr>");
            }
            else
            {
                  echo("       
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center><input type=\"checkbox\" name=\"name[]\" value=\"$field1\"></td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field3</td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field4</td>
                  <td bgcolor='#E3EAF4'><FONT face=arial size=2><center>$field5</td>
                  </tr>");
            }
      ;}
$result1 = mysql_query( "SELECT Round, RName, wClassesDet.Fee FROM wClassesDet, wClasses WHERE wClasses.Event = '$prod->Event'
                                    and wClassesDet.EClass = wClasses.EClass and wClasses.Event = wClassesDet.Event and wClassesDet.EClass =
                                    '$row[EClass]' and NoPay < 1 and wClasses.Race >= 1 ORDER BY `Round`") or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result1);
      while ($get_info = mysql_fetch_row($result1))
      {
            print "<tr>\n";
            print "<td></td>";
            print "<td></td>";
            foreach ($get_info as $field)
            print "\t<td><font face=arial size=2/><div align=\"center\">$field</div></font></td>\n";
            print "</tr>\n";
      }
      }
      print "</table><br>\n";
      }}

}

?>
            </th>
      </tr>
</table>

<br>

<table width="768" border="1" bordercolor="#000000" bgcolor="#AEAEFF">
      <tr>
            <th width="8" bordercolor="#AEAEFF" scope="col">&nbsp;</th>
            <th width="238" align="left" valign="top" bordercolor="#AEAEFF" scope="col"><div align="left"><span class="style16">
                  <u>Other Items</u></span><span class="style15"> (select all that apply)</span></div></th>
            <td width="500" bordercolor="#AEAEFF"><div align="right"></div></td>
      </tr>
</table>

<br>

<table width="593" border="0">
      <tr>
            <th width="682" scope="col"><span class="style24"><strong><span class="style35">
<?
/*------------------------------------------------------------------------
Other Event Fees(section with chechbox & Qty)
-------------------------------------------------------------------------*/

echo("
      <table width=\"150\" border=\"0\">
            <tr>
                  <th width=\"65\"><div align=\"left\"> </U></div></th></span>
                  <th width=\"50\"></th>
            <table width=440 border=0>\n
                  <td><FONT face=tahoma size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\n
                  <td bgcolor='cccccc'><FONT face=tahoma size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\n
                  <td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;Description&nbsp; </td>\n
                  <td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;&nbsp;&nbsp;Fee&nbsp;&nbsp;&nbsp;&nbsp; </td>\n
                  <td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;&nbsp;&nbsp;Qty&nbsp;&nbsp;&nbsp;&nbsp; </td>\n");

$result1 = mysql_query( "SELECT wClassesDet.EClass, wClassesDet.Fee, Round FROM wClassesDet, wClasses WHERE
                                    wClasses.Event = '$prod->Event' and wClasses.ProducerID= '$prod->ProducerID' and wClasses.Association =
                                    '$prod->Association' and wClassesDet.EClass = wClasses.EClass and wClasses.Event = wClassesDet.Event and
                                    wClasses.Race = 0" ) or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result1);
if (!$result1)
{
      echo("<p>Error performing query: " . mysql_error() . "</p>");
      exit();
}
      if ($num_rows >=1)
      {      
            while ($row = mysql_fetch_array($result1, MYSQL_ASSOC))
            {
                  $field1= "$row[EClass]$row[Round]";
                  $field2= $row["Fee"];
                  $field3= $row["EClass"];
                  echo("       
                        <tr>
                              <td></td>
                              <td bgcolor='#E3EAF4'><center><input type=\"checkbox\" name=\"fee[]\" value=\"$field1\"></td>
                              <td bgcolor='#E3EAF4'><center>$field3</td>
                              <td bgcolor='#E3EAF4'><center>$field2</td>
                              <td bgcolor='#E3EAF4'><center><input type=\"text\" name=\"qty[]\" size=\"2\" maxlength=\"2\"\"></td>
                        </tr>");
            }
      }
      else
      {
            echo "</table>";
            echo "<b>No other items for this race.</div></font>\n";
      }
?>
</span></strong></span>
            </th>
      </tr>
</table>

<br>

<table width="768" border="1" bordercolor="#000000" bgcolor="#AEAEFF">
      <tr>
            <th width="8" bordercolor="#AEAEFF" scope="col">&nbsp;</th>
            <th width="238" align="left" valign="top" bordercolor="#AEAEFF" scope="col"><div align="left"><span class="style16"><u>
                  Event Costs</u></span><span class="style15"> (set fee)</span></div></th>
            <td width="500" bordercolor="#AEAEFF"><div align="right"></div></td>
      </tr>
</table>

<br>

<table width="714" border="0">
      <tr>
            <th width="708" scope="col"><p class="style24">
          <?
echo("
<table width=\"150\" border=\"0\">
      <tr>
            <th width=\"65\"><div align=\"left\"> </U></div></th></span>
            <th width=\"50\"></th>");      
$result1 = mysql_query( "SELECT wItems.Description, wItems.Fee FROM wItems WHERE wItems.Event = '$prod->Event' and
wItems.ProducerID= '$prod->ProducerID' and wItems.Association = '$prod->Association'" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result1);
echo ("
<table width=350 border=0>\n
      <td bgcolor='cccccc'><FONT face=arial size=2><center>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Description&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp; </td>\n
      <td bgcolor='cccccc'><FONT face=Arial size=2><center>&nbsp;&nbsp;&nbsp;&nbsp;<b>Fee&nbsp;&nbsp;&nbsp;&nbsp; </td>\n");
if ($num_rows >= 1 ){
while ($get_info = mysql_fetch_row($result1)){
echo ("
      <tr>\n
            ");
foreach ($get_info as $field1)
echo ("
            \t<td bgcolor='#D1DCED'><font face=arial size=2/><div align=\"center\"><b>$field1</div></font></td>\n
      ");
}
print "</table>\n";
$total=0;

    $result=mysql_query("SELECT Fee FROM wItems WHERE wItems.Event = '$prod->Event' and
      wItems.ProducerID= '$prod->ProducerID' and wItems.Association = '$prod->Association'");
    if(!$result) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
        $product_fee=$row["Fee"];
        $total+=$product_fee;
    }
print "<table width=350 border=0>\n";
print "<tr><div align=\"right\"><hr width=\"320\"></tr>\n";
print "<td><center>Total Cost of Event Fees : </td>";
print "<td><center>$ $total.00</td>";
print "</tr>\n";
print "</table>\n";
}
else {
print "<tr>\n";
print "<td></td>";
print "\t<td><font face=arial size=2/><div align=\"center\">   <b>No event charges for this race.</div></font></td>\n";
print "</tr>\n";
print "</table>\n";

}
?>
            </p>
              </th>
        </tr>
  </table>
      <table>      
<tr>
      <td width="335"></td>
      <td width="122"><br><input type="submit" value="Next Step"></td>
</tr>
</table>
</form><? }?>
0
 

Author Comment

by:asmaynard
ID: 13522881
The include("../application.php"); at the beginning of the first page contains the save_orderinfo and load_orderinfo, I will only post those functions as the rest aren't pertinent to this:


function save_orderinfo(&$frm) {
/* this function saves the order information into the session variable
 * $SESSION["orderinfo"].  it is used in the purchase confirmation stage */

      global $USER;

      $order = new Object();
      
if (isset($_POST['child_name']))  
       {$order->customer = $frm["child_name"];}
 if (empty($_POST['child_name']))
      {$order->customer = $USER["user"]["firstname"] . " " . $USER["user"]["lastname"];}
      $order->contact = $USER["user"]["phone"];
      $order->address = $USER["user"]["address"];
      $order->city = $USER["user"]["city"];
      $order->state = $USER["user"]["state"];            
      $order->zip = $USER["user"]["zip"];
      $order->horse = $frm["horse"];
      $order->child_name = $frm["child_name"];
for($i=0;$i<sizeof($frm['name']);$i++)$order->checkbox[]=$frm['name'][$i];            
    foreach ($frm['fee'] as $index => $productname)
     {
       $order->checkbox_1[]['fee'] = $productname;
       $order->checkbox_1[]['qty'] = (empty($frm['qty'][$index]) ? 0 : intval($frm['qty'][$index]));
     }
            
      $USER["orderinfo"] = &$order;
}

function load_orderinfo() {
/* this function is the counterpart to save_orderinfo.  it is used to
 * retrieve the order information in the complete order page */

      global $USER;

      if (empty($USER["orderinfo"])) {
            return false;
      } else {
            return $USER["orderinfo"];
      }
}
0
 

Author Comment

by:asmaynard
ID: 13522885
This is the page(purchase_confirm.php) that load's the order information and calls the confirmation page.

<?
include("../application.php");
$prod = load_product($_REQUEST["event"]);
$id = nvl($_REQUEST["event"], 1);
$qid_p = get_event();
 if ($info = load_orderinfo()) {
      $custid = $USER["user"]["custid"];
      $customer = $info->customer;
      $contact = $info->contact;
      $address = $info->address;
      $city = $info->city;
      $state = $info->state;
      $zip = $info->zip;
      $horse = $info->horse;
      $event = $prod->Event;
for($i=0;$i<sizeof($info->checkbox);$i++)$checkbox[]=$info->checkbox[$i];
   $checkbox_1 = array(); // this is to ensure it starts off clean...
     foreach($info->checkbox_1 as $index => $option)
       $checkbox_1[] = $option; // simple now!


} else {
      $custid = $USER["user"]["custid"];
      $customer = $USER["user"]["firstname"] . " " . $USER["user"]["lastname"];
      $contact = $USER["user"]["phone"];
      $address = $USER["user"]["address"];
      $city = $USER["user"]["city"];
      $state = $USER["user"]["state"];
      $zip = $USER["user"]["zip"];
      $horse = $USER["user"]["horse"];
      $checkbox = $USER["user"]["name[]"];

}
            $DOC_TITLE = "MyMarket Purchase Confirmation";
$frm = $_REQUEST;
$frm = $_POST;

      $qid = get_cart_items();
      $DOC_TITLE = "MyMarket Purchase Confirmation";            
      $template_to_show = "templates/purchase_confirmation1.php";

include("$CFG->templatedir/header.php");
include($template_to_show);

?>
0
 

Author Comment

by:asmaynard
ID: 13522891
And finally the purchase confirmation page(purchase_confirmation1.php) where I need to have the Item and Quantity printed.  Thanks for all your help!

<html>
<table width="798" border="0">
  <tr>
    <th width="741" scope="col">&nbsp;</th>
  </tr>
</table>
<?
for($no=0;$no<count($checkbox_1);$no++)
{
  $result=mysql_query("SELECT wClassesDet.Fee, wClassesDet.EClass FROM wClassesDet, wClasses WHERE      
  wClasses.Event = '$prod->Event' and ClassRnd = '".$checkbox_1[$no]['name']."' and
  wClasses.ProducerID='$prod->ProducerID' and wClasses.Association = '$prod->Association'");
  if(!$result)
  {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
  }
  if($row=mysql_fetch_array($result, MYSQL_ASSOC))
  {
     $product_fee=$row["Fee"];
     $round_name=$row["EClass"];
     
     $totalfee = $checkbox_1[$no]['qty'] * $product_fee;
     echo $checkbox_1[$no]['name'].": ";
     echo $checkbox_1[$no]['qty']. " x $product_fee = $totalfee<br/>";
  }
  }
  ?>

<?
for($no=0;$no<count($checkbox);$no++){
 $result=mysql_query("SELECT wClassesDet.Fee, wClassesDet.EClass FROM wClassesDet, wClasses WHERE wClasses.Event = '$prod->Event' and
      ClassRnd = '$checkbox[$no]' and wClasses.ProducerID= '$prod->ProducerID' and wClasses.Association = '$prod->Association'");
    if(!$result) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    if($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
        $product_fee=$row["Fee"];
            $round_name=$row["EClass"];
      }      
}
?>

<?
for($no=0;$no<count($checkbox);$no++){
 $result=mysql_query("SELECT wClassesDet.Round FROM wClassesDet, wClasses WHERE
       ClassRnd = '$checkbox[$no]' and wClassesDet.Event = '$prod->Event' and       wClasses.ProducerID= '$prod->ProducerID'
      and wClasses.Association = '$prod->Association'");
    if(!$result) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    if($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
            $product_round=$row["Round"];
      }      
}
?>

<?
$total=0;

foreach($info->checkbox as $product_name) {
    // probably ought to escape $product_name here, to prevent SQL injection attacks
    $result=mysql_query("SELECT wClassesDet.Fee FROM wClassesDet, wClasses WHERE wClassesDet.Event = '$prod->Event'
      and ClassRnd = '$product_name' and wClasses.ProducerID= '$prod->ProducerID' and wClasses.Association = '$prod->Association'");
    if(!$result) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    if($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
        $product_fee=$row["Fee"];
        $total+=$product_fee;
    }
}      
?>

<?
$event_total=0;

    $result=mysql_query("SELECT Fee FROM wItems WHERE wItems.Event = '$prod->Event' and
      wItems.ProducerID= '$prod->ProducerID' and wItems.Association = '$prod->Association'");
    if(!$result) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
        $event_fee=$row["Fee"];
        $event_total+=$event_fee;
    }
?>

<?
$total=0;

foreach($info->checkbox as $product_name) {
    // probably ought to escape $product_name here, to prevent SQL injection attacks
    $result=mysql_query("SELECT wClassesDet.Fee FROM wClassesDet, wClasses WHERE wClassesDet.Event = '$prod->Event'
      and ClassRnd = '$product_name' and wClasses.ProducerID= '$prod->ProducerID' and wClasses.Association = '$prod->Association'");
    if(!$result) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    if($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
        $product_fee=$row["Fee"];
        $total+=$product_fee;
    }
}      

?>
<? $grand_total= ($event_total + $total)      ;?>


<?
      $order = load_orderinfo();


/* we will create the order in our database, then try to authorize the
 * payment.  if all was successful, the user's order will have been
 * completed.
 */
/******************************************************************************
 * FUNCTIONS
 *****************************************************************************/

function create_order(&$order) {

global $USER, $CART, $round_name, $product_round, $checkbox, $prod;



for($no=0;$no<count($checkbox);$no++){
 $result_1=mysql_query("SELECT wClassesDet.Fee, wClassesDet.EClass, wClassesDet.Round FROM wClassesDet, wClasses WHERE
       ClassRnd = '$checkbox[$no]' and wClassesDet.Event = '$prod->Event' and       wClasses.ProducerID= '$prod->ProducerID'
      and wClasses.Association = '$prod->Association'");
    if(!$result_1) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    if($row=mysql_fetch_array($result_1, MYSQL_ASSOC)) {
        $product_fee=$row["Fee"];
            $round_name=$row["EClass"];
            $product_round=$row["Round"];


/* save order information*/
      $orderid = db_insert_id();

            db_query("
      INSERT INTO wJournal (
            CustID, ProducerID, Association, Event, JDate, RName, Horse, Round, Memo, Price
      ) VALUES (
             '{$USER["user"]["custid"]}'
            ,'$prod->ProducerID'
            ,'$prod->Association'
            ,'$prod->Event'
            ,now()
            ,'$order->customer'
            ,'$order->horse'
            ,'$product_round'
            ,'$round_name'
            ,'$product_fee'

      ) ");


}
}
}



$order = load_orderinfo();
$orderid = create_order($order);

?>
<table width="768" border="1" bordercolor="#000000" bgcolor="#AEAEFF">
  <tr>
    <th width="8" bordercolor="#AEAEFF" scope="col">&nbsp;</th>
    <th width="240" align="left" valign="top" bordercolor="#AEAEFF" scope="col"><div align="left" class="style3"><u>Class &amp; Round Information: </u> </div></th>
    <td width="498"></td>
  </tr>
</table>
<table width="768" border="0">
  <tr>
    <th width="762" scope="col"><table cellspacing="1" cellpadding="3">
        <tr>
          <td width="160" class="label">NAME</td>
          <td width="160" class="label">HORSE</td>
          <td width="161" class="label">ROUND</td>
          <td width="159" class="label">Round &amp; Other Items </td>
          <td width="1" align="right" class="label">&nbsp;</td>
          <td width="1" align="right" class="label"><div align="left"></div></td>
          <td width="75" align="right" class="label">Price</td>
        </tr>
        <tr>
          <td valign="top" class="normal"><? pv($customer) ?></td>
          <td valign="top" class="normal"><?=nl2br(ov($horse)) ?></td>
          <td valign="top" class="normal"><?
for($no=0;$no<count($checkbox);$no++){
 $result=mysql_query("SELECT wClassesDet.Fee, wClassesDet.EClass FROM wClassesDet, wClasses WHERE wClasses.Event = '$prod->Event' and
      ClassRnd = '$checkbox[$no]' and wClasses.ProducerID= '$prod->ProducerID' and wClasses.Association = '$prod->Association'");
    if(!$result) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    if($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
        $product_fee=$row["Fee"];
            $round_name=$row["EClass"];
      echo "$round_name<br>";
      }      
}
?>

&nbsp;</td>
          <td valign="top" class="normal"><?
for($no=0;$no<count($checkbox);$no++){
 $result=mysql_query("SELECT wClassesDet.Round FROM wClassesDet, wClasses WHERE
       ClassRnd = '$checkbox[$no]' and wClassesDet.Event = '$prod->Event' and       wClasses.ProducerID= '$prod->ProducerID'
      and wClasses.Association = '$prod->Association'");
    if(!$result) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    if($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
            $product_round=$row["Round"];
echo "$product_round<br>";
      }      
}
?></td>
          <td class="normal" align="right">&nbsp;</td>
          <td class="normal">&nbsp;</td>
          <td align="right" valign="top" class="normal"><?
for($no=0;$no<count($checkbox);$no++){
 $result=mysql_query("SELECT wClassesDet.Fee, wClassesDet.EClass, wClassesDet.Round FROM wClassesDet, wClasses WHERE
       ClassRnd = '$checkbox[$no]' and
       wClassesDet.Event = '$prod->Event' and
      wClasses.ProducerID= '$prod->ProducerID' and wClasses.Association = '$prod->Association'");
    if(!$result) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    if($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
        $product_fee=$row["Fee"];
            $product_name=$row["EClass"];
            $product_round=$row["Round"];
      echo "$&nbsp;$product_fee<br>";
      }      
}
?>
          </td>
        </tr>
        <tr>
          <td colspan="6"></td>
          <td></td>
        </tr>
        <tr>
          <td colspan="6"></td>
          <td><hr size="1"></td>
        </tr>
        <tr>
          <td colspan="6" class="label" align="right">Total Cost for Rounds:</td>
          <td class="normal" align="right"><?=$CFG->currency ?>
              <?
$total=0;

foreach($info->checkbox as $product_name) {
    // probably ought to escape $product_name here, to prevent SQL injection attacks
    $result=mysql_query("SELECT wClassesDet.Fee FROM wClassesDet, wClasses WHERE wClassesDet.Event = '$prod->Event'
      and ClassRnd = '$product_name' and wClasses.ProducerID= '$prod->ProducerID' and wClasses.Association = '$prod->Association'");
    if(!$result) {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
    }
    if($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
        $product_fee=$row["Fee"];
        $total+=$product_fee;
    }
}      

       ?>
              $<? print_price($total) ?></td>
        </tr>
    </table></th>
  </tr>
</table>
<table width="767" border="0">
  <tr>
    <th scope="col"><form name="form1" method="post" action="http://www.payraces.com/shopping/register.php?event=<?=$prod->Event?>&prodid=<?=$prod->ProducerID?>&assoc=<?=$prod->Association?>">
    <input type="submit" value="Add Another Horse/Rider">
      </form></th>
    <th scope="col"><form name="form2" method="post" action="http://www.payraces.com/shopping/index.php">
    <input type="submit" value="Register for Another Event">
      </form></th>
    <th scope="col"><form name="form3" method="post" action="http://www.payraces.com/shopping/ledger.php">
    <input type="submit" value="Pay for Races">
      </form></th>
  </tr>
</table>
</html>
0
 
LVL 17

Expert Comment

by:davebytes
ID: 13523300
I'll keep this in snippets.  I'm assuming you've done SOME verification that the data from the form is getting passed around/stored in session properly, and not coming up blank or escaped or something...

first block of code to change, the original form:
---------------------------------------------------
     if ($num_rows >=1)
     {
           $i = 0;    
          while ($row = mysql_fetch_array($result1, MYSQL_ASSOC))
          {
               $field1= "$row[EClass]$row[Round]";
               $field2= $row["Fee"];
               $field3= $row["EClass"];
               echo("      
                    <tr>
                         <td></td>
                         <td bgcolor='#E3EAF4'><center><input type=\"checkbox\" name=\"fee[$i]\" value=\"$field1\"></td>
                         <td bgcolor='#E3EAF4'><center>$field3</td>
                         <td bgcolor='#E3EAF4'><center>$field2</td>
                         <td bgcolor='#E3EAF4'><center><input type=\"text\" name=\"qty[$i]\" size=\"2\" maxlength=\"2\"\"></td>
                    </tr>");
               $i++;
          }
     }
--------------------------------------------
What I did there: added EXPLICIT $i indices to the arrays.  Otherwise they don't correlate.

Next is the output collection/calc, again snippet:
---------------------------------------------
<?
// instead of: for($no=0;$no<count($checkbox_1);$no++)
// let's try something that makes it more legible:
foreach($checkbox_1 as $no => $option)
{
  $result=mysql_query("SELECT wClassesDet.Fee, wClassesDet.EClass FROM wClassesDet, wClasses WHERE      
  wClasses.Event = '$prod->Event' and ClassRnd = '".$option['fee']."' and
  wClasses.ProducerID='$prod->ProducerID' and wClasses.Association = '$prod->Association'");
  if(!$result)
  {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
  }
  if($row=mysql_fetch_array($result, MYSQL_ASSOC))
  {
     $product_fee=$row["Fee"];
     $round_name=$row["EClass"];
     
     $totalfee = $option['qty'] * $product_fee;
     echo $option['fee'].": ";
     echo $option['qty']. " x $product_fee = $totalfee<br/>";
  }
  }
  ?>
---------------------------------------------
What I changed:
- the for loop to a foreach, so code is MUCH cleaner
- you were STILL using 'name' as an index, instead of the new name 'fee'.  So the query was probably bogus.

Try those two localized pieces, I can't actually run your code, but having it gave me some things to try in prototypes (I made a quick two-file form entry, which gave me the first fix, and then I noticed the use of 'name' which gave me the second...).

If you are getting ANY errors of undefined variable/index, triple check the code going backward to make sure arrays are getting copied & stored properly.  echo and die() are your friend. ;)

-d
0
 

Author Comment

by:asmaynard
ID: 13523483
I've been working with your code and I am now able to return the items name, however, the $option["fee"] array is returning the items name  "x 0.01 = 0", I've echoed $option["fee"] in various places trying to figure out where the x 0.01 = 0 is appended but do not see where. The Qty is returned correctly as well but the value of the item is still wrong, I figure that since the $option["fee"] has the appended x0.01 the SQL query is screwing up.  Is the "x 0.01" needed?  

Also, I'm still receiving undefined indexes qty and fee on the purchase_confirmation1.php.  Being new to PHP, and programming in general, I've gone back over the code time and time again trying to see what differs between code that works and this,  I see that when the form info is saved into the order object both qty and fee are defined by:

      $order->checkbox_1[]['fee'] = $productname;
      $order->checkbox_1[]['qty'] = (empty($frm['qty'][$index]) ? 0 : intval($frm['qty'][$index]));

but when it's loaded I'm using this:

   $checkbox_1 = array(); // this is to ensure it starts off clean...
     foreach($info->checkbox_1 as $index => $option)
       $checkbox_1[] = $option; // simple now!

I'm guessing the undefined indexes are caused by naming the variable $checkbox_1[] instead of $checkbox_1[]['fee'] and $checkbox_1[]['qty'].  Is there a way to load ['fee'] and ['qty']?  Thank you for your patience in working with me, your help is greatly appreciated.
0
 
LVL 17

Expert Comment

by:davebytes
ID: 13525103
strange.  lemme work backwards:

     foreach($info->checkbox_1 as $index => $option)
       $checkbox_1[] = $option; // simple now!

should work fine.  $checkbox_1[0] for example is an array itself with two elements.  Saying:
       $checkbox_1[] = $option; // simple now!
should be copying the sub-array ($option) into the next open element of checkbox_1.  Where exactly does it say the undefined indicies are being used?  on the original copy into $order?

You should be able to do a print_r($info->checkbox_1);  before that to see that the array 'looks right'.  Otherwise, we can do an explicit field copy if it looks right but for some reason isn't copying properly.
     foreach($info->checkbox_1 as $index => $option)
     {
       $checkbox_1[]['fee'] = $option['fee'];
       $checkbox_1[]['qty'] = $option['qty'];
     }
BUT I WOULDN'T DO THAT unless it fixes something, as it should be unneeded.  And it clarifies that you already have a sub-array with data you are just copying over one by one.

Note, you could in fact do:
  $checkbox_1 = $info->checkbox_1;
There's no real reason not to, actually.  The 'by hand copy' is redundant.

Okay.  Now, for the 'fee' field at some point being 'x 0.01', that's obviously something really screwed up. ;)  Ummm.  At what point, which file, what step does the 'fee' field no longer say the option name, but that garbage?  And again, I'm working blind, so I don't see the actual step-by-step of the forms on screen.  Sounds like somewhere maybe the wrong data is being saved, or read in, for those fields.  You >should< be able to easily nail down >exactly< when the last time is that you have the 'fee' field echoing out properly, and when it changes to having the wrong data.  That'll tell you the problem area, then maybe I can help debug further.

-d
0
 

Author Comment

by:asmaynard
ID: 13525655
I'm getting the undefined indicies on the template purchase_confirmation1.php when I run this code:

foreach($checkbox_1 as $no => $option)
{

  $result=mysql_query("SELECT wClassesDet.Fee, wClassesDet.EClass FROM wClassesDet, wClasses WHERE      
  wClasses.Event = '$prod->Event' and ClassRnd = '$option[fee]' and
  wClasses.ProducerID='$prod->ProducerID' and wClasses.Association = '$prod->Association'");
  if(!$result)
  {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
  }
  if($row=mysql_fetch_array($result, MYSQL_ASSOC))
  {
     $product_fee=$row["Fee"];
     $round_name=$row["EClass"];
     
     $totalfee = $option['qty'] * $product_fee;
     echo $option["fee"];
     echo $option['qty']. " x $product_fee = $totalfee<br/>";
  }
  }


and this is the error message it it's entirety:

PHP Notice: Undefined index: qty in E:\web\payracescom\htdocs\shopping\templates\purchase_confirmation1.php on line 37 PHP Notice: Undefined index: qty in E:\web\payracescom\htdocs\shopping\templates\purchase_confirmation1.php on line 38 PHP Notice: Undefined index: fee in E:\web\payracescom\htdocs\shopping\templates\purchase_confirmation1.php on line 23 PHP Notice: Undefined index: fee in E:\web\payracescom\htdocs\shopping\templates\purchase_confirmation1.php on line 25

So the errors are in the SQL query and the echo section.

I've changed

   $checkbox_1 = array(); // this is to ensure it starts off clean...
     foreach($info->checkbox_1 as $index => $option)
       $checkbox_1[] = $option; // simple now!

on purchase_confirm.php to

print_r($info->checkbox_1);  
$checkbox_1 = $info->checkbox_1;

which does exactly the same the foreach.  The print_r is returning

Array ( [0] => Array ( [fee] => Non Member Fee1 ) [1] => Array ( [qty] => 1 ) )

So  [1]  is the culprit, which I'm gessing is being appended in the save_orderinfo function here somewhere

    foreach ($frm['fee'] as $index => $productname)
     {
       $order->checkbox_1[]['fee'] = $productname;
       $order->checkbox_1[]['qty'] = (empty($frm['qty'][$index]) ? 0 : intval($frm['qty'][$index]));
     }

I have tried echoing 'fee' in different parts in this foreach loop but either recieve all kinds of errors keeping the page from loading or only "Array" is echoed.  Thanks for all your help, you've taught me alot about how to debug my code.
0
 
LVL 17

Expert Comment

by:davebytes
ID: 13526904
instead of echoing an array, use print_r to print the array variable out, OR echo serialize($var) -- either will work for showing you the contents of the array...

on the last thing, I just noticed the error.

    foreach ($frm['fee'] as $index => $productname)
     {
       $order->checkbox_1[]['fee'] = $productname;
       $order->checkbox_1[]['qty'] = (empty($frm['qty'][$index]) ? 0 : intval($frm['qty'][$index]));
     }

that won't work.  instead, let's try:

    $i = 0;
    foreach ($frm['fee'] as $index => $productname)
     {
       $order->checkbox_1[$i]['fee'] = $productname;
       $order->checkbox_1[$i]['qty'] = (empty($frm['qty'][$index]) ? 0 : intval($frm['qty'][$index]));
       $i++;
     }

That'll rid you of that issue.  Not sure what else that'll fix, but it's certainly cascading errors throughout the rest of the process.

Higher up, the query code is incorrect.  [fee] needs to be quoted to ['fee']...

  $result=mysql_query("SELECT wClassesDet.Fee, wClassesDet.EClass FROM wClassesDet, wClasses WHERE      
  wClasses.Event = '$prod->Event' and ClassRnd = '$option[fee]' and
  wClasses.ProducerID='$prod->ProducerID' and wClasses.Association = '$prod->Association'");
 
Let's try this... I'm doing it 'longhand' so it is more legible for me pasting in here...

  $query = "SELECT wClassesDet.Fee, wClassesDet.EClass FROM wClassesDet, wClasses";
  $query .= " WHERE wClasses.Event = '".$prod->Event."' and ClassRnd = '".$option['fee']
  $query .= " and wClasses.ProducerID='".$prod->ProducerID."' and wClasses.Association = '".$prod->Association."'";
  $result = mysql_query($query);

See if that helps.

-d
0
 

Author Comment

by:asmaynard
ID: 13527043
Adding the $i=0 solved all the error messages I was having.  I was playing with the form and noticed that the fee is returned as $0.01 for the first checkbox/qty only, all following checkboxes have the right amounts and qtys and are multiplied together correctly.  I added

$product_fee= 0;

above the:

foreach($checkbox_1 as $no => $option)
{
$query = "SELECT wClassesDet.Fee, wClassesDet.EClass FROM wClassesDet, wClasses";
  $query .= " WHERE wClasses.Event = '".$prod->Event."' and ClassRnd = '".$option['fee']."'";
  $query .= " and wClasses.ProducerID='".$prod->ProducerID."' and wClasses.Association = '".$prod->Association."'";
  $result = mysql_query($query);

  if(!$result)
  {
        echo("<p>Error performing query: " . mysql_error() . "</p>");
        exit();
  }
  if($row=mysql_fetch_array($result, MYSQL_ASSOC))
  {
     $product_fee=$row["Fee"];
       echo "$product_fee";
      
     $round_name=$row["EClass"];
     
     $totalfee = $option['qty'] * $product_fee;
     echo $option["fee"];
     echo $option['qty']. " x $product_fee = $totalfee<br/>";
  }
  }


thinking that maybe it was being initialized wrong, but that didn't solve anything.  Also, how do I account for if no checkbox/qty were selected.  I've been able to save the order info right by using:

if (isset($_POST['fee'])) {
    $i = 0;
    foreach ($frm['fee'] as $index => $productname)
     {
       $order->checkbox_1[$i]['fee'] = $productname;
       $order->checkbox_1[$i]['qty'] = (empty($frm['qty'][$index]) ? 0 : intval($frm['qty'][$index]));
       $i++;
     }}

and tried to get this to work when loading the order:

 if ($info = load_orderinfo()) {
      $custid = $USER["user"]["custid"];
      $customer = $info->customer;
      $contact = $info->contact;
      $address = $info->address;
      $city = $info->city;
      $state = $info->state;
      $zip = $info->zip;
      $horse = $info->horse;
      $event = $prod->Event;
       for($i=0;$i<sizeof($info->checkbox);$i++)$checkbox[]=$info->checkbox[$i];
if (isset($_POST['$info->checkbox_1']))  
{
print_r($info->checkbox_1);  
$checkbox_1 = $info->checkbox_1;
}

but the "isset" is never initalized, I guess because there is no form submitted just a page transfer.  Hopefully we can get this working soon.  Thanks!!
0
 
LVL 17

Accepted Solution

by:
davebytes earned 2000 total points
ID: 13527104
you can just use !empty($some_array) if you just want to test that an array has entries in it and isn't empty...

as for fee, you mean:
 echo "$product_fee";
is outputting 0.01 for the first entry, but subsequent ones are proper?

maybe change that for better debugging... something like:
  echo "option $no (".$option['fee'].") = $product_fee<br/>".serialize($row)."<br/>";
... or something like that.

Only thing I could imagine is if it's really pulling 0.01 from the database.. Otherwise, not sure.  Keep throwing in debugging statements.

-d
0
 

Author Comment

by:asmaynard
ID: 13527481
Dave,
I finally got the Qty/Checkbox to work, I had used the serialize($row) and saw the SQL statement was wrong, I changed somethings around and it worked!!  Thanks for all your help, there was no way I would've ever been able to figure that out with out all of your help.  One last thing, when using !empty($some_array) how do I create an if statement, such as:

   if $info->checkbox_1 isset(don't know the syntax for what to but here in this situation)
       {
           $checkbox_1 = $info->checkbox_1;
        }

If no checkbox/qty is selected on the checkout form when I reach to confirmation page I receive these errors:

PHP Notice: Undefined property: checkbox_1 in E:\web\payracescom\htdocs\shopping\purchase_confirm.php on line 17 PHP Notice: Undefined property: checkbox_1 in E:\web\payracescom\htdocs\shopping\purchase_confirm.php on line 18 PHP Warning: Invalid argument supplied for foreach() in E:\web\payracescom\htdocs\shopping\templates\purchase_confirmation1.php on line 23

0
 

Author Comment

by:asmaynard
ID: 13532556
I finally got everything working correctly,  it was a matter of using isset with the correct variable.  I appreciate all of your help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question