Solved

$_SESSION number 1 is lost somehow when i go to add the third item to the invoice ?

Posted on 2004-09-23
1
160 Views
Last Modified: 2010-05-18
$_SESSION
number 1 is lost somehow when i go to add the third item to the invoice ?










    function additem(){

         if($_SESSION['totalitems'] > 0){

          $totalitems = $_SESSION['totalitems'] + 1;
          $_SESSION['totalitems'] = $totalitems; //keep track of total items
          $_SESSION['qty'.$totalitems]  = $_REQUEST['qty'];
          $_SESSION['interchangenumber'.$totalitems]  = $_REQUEST['interchangenumber'];
          $_SESSION['interchangeid'.$totalitems]  = $_REQUEST['interchangeid'];
          $_SESSION['description'.$totalitems]  = $_REQUEST['description'];
          $_SESSION['rate'.$totalitems]  = $_REQUEST['rate'];
          $_SESSION['amount'.$totalitems]  = $_REQUEST['amount'];
          $_SESSION['taxable'.$totalitems]  = $_REQUEST['taxable'];
          $_SESSION['notes'.$totalitems]  = $_REQUEST['notes'];
          $_SESSION['partid'.$totalitems]  = $_REQUEST['partid'];

         }else{
          //add first item SO use the 1 after each item

          $_SESSION['qty1']  = $_REQUEST['qty'];
          $_SESSION['interchangenumber1']  = $_REQUEST['interchangenumber'];
          $_SESSION['interchangeid1']  = $_REQUEST['interchangeid'];
          $_SESSION['description1']  = $_REQUEST['description'];
          $_SESSION['rate1']  = $_REQUEST['rate'];
          $_SESSION['amount1']  = $_REQUEST['amount'];
          $_SESSION['taxable1']  = $_REQUEST['taxable'];
          $_SESSION['notes1']  = $_REQUEST['notes'];
          $_SESSION['partid1']  = $_REQUEST['partid'];
          $_SESSION['tracking1']  = $_REQUEST['tracking'];
          $_SESSION['vendorid1']  = $_REQUEST['vendorid'];
          $_SESSION['totalitems']  = 1;


            }


         }








   function showallitems(){

         $items = $_SESSION['totalitems'] + 1;
         for($a=1; $a < $items; $a++){

             $totalitems = $a;


echo '
<form name="remove'.$totalitems.'" action="" method="post">
<table width="73%" border="1" cellspacing="0" cellpadding="0" bordercolor="#000066">
  <tr bgcolor="#99CCFF" bordercolor="#000066">
    <td width="10%" align="center" valign="center" true styleid="StyleQty" bgcolor="#990000" bordercolor="#FFFFFF"><font color="#FFFFFF">Hidden</font></td>
    <td width="10%" align="center" valign="center" true styleid="StyleQty"><font face="Verdana" size="-1" color="#000000">Quantity</font></td>
      <td width="10%" align="center" valign="center" true styleid="StyleQty">PartID</td>
    <td width="14%" align="center" valign="center" true styleid="StyleQty">Interchange
      # </td>
    <td width="37%" align="center" valign="center" true styleid="StyleItemDesc">
      <font face="Verdana" size="-1" color="#000000">Description</font> </td>
    <td width="8%" align="center" valign="center" true styleid="StyleRate"> <font face="Verdana" size="-1" color="#000000">Rate</font>
    </td>
    <td width="6%" align="center" valign="center" true styleid="StyleItemAmount">
      <font face="Verdana" size="-1" color="#000000">Amount</font> </td>
    <td width="15%" align="center" valign="center" true styleid="StyleTaxFlag">
      <font face="Verdana" size="-1" color="#000000">Tax&nbsp;</font> </td>
  </tr>
  <tr bgcolor="#99CCFF" bordercolor="#000066">
    <td width="10%" align="center" valign="center" true styleid="StyleQty" bgcolor="#990000" bordercolor="#FFFFFF" height="13">&nbsp;
    </td>
    <td width="10%" align="center" valign="center" true styleid="StyleQty" height="13">
      <input type="text" name="qty'.$totalitems.'" size="4" maxlength="3" value="'.$_SESSION['qty'.$totalitems].'" readonly>
    </td>
    <td width="10%" align="center" valign="center" true styleid="StyleQty" height="13">
        <input type="text" name="interchangeid'.$totalitems.'" value="'.$_SESSION['interchangeid'.$totalitems].'" size="9" readonly>
      <br>
      </td>
    <td width="14%" align="center" valign="center" true styleid="StyleQty" height="13"><font face="Verdana" size="-1" color="#000000">
      <input type="text" name="interchangenumber'.$totalitems.'" value="'.$_SESSION['interchangenumber'.$totalitems].'" size="13" readonly>
      </font></td>
    <td width="37%" align="center" valign="center" true styleid="StyleItemDesc" height="13"><font face="Verdana" size="-1" color="#000000">
      <input type="text" name="description'.$totalitems.'" size="45" value="'.$_SESSION['description'.$totalitems].'" readonly>
      </font></td>
    <td width="8%" align="center" valign="center" true styleid="StyleRate" height="13"><font face="Verdana" size="-1" color="#000000">
      <input type="text" name="rate'.$totalitems.'" size="8"  value="'.$_SESSION['rate'.$totalitems].'" readonly>
      </font></td>
    <td width="6%" align="center" valign="center" true styleid="StyleItemAmount" height="13"><font face="Verdana" size="-1" color="#000000">
      <input type="text" name="amount'.$totalitems.'" size="7"  value="'.$_SESSION['amount'.$totalitems].'" readonly>
      </font></td>
    <td width="15%" align="center" valign="center" true styleid="StyleTaxFlag" height="13">NT</td>
  </tr>
</table>
<table width="73%" border="1" cellspacing="0" cellpadding="0" bordercolor="#000066">
  <tr>
    <td bgcolor="#990000" width="29%">
      <div align="center"><font color="#FFFFFF">Hidden Notes about Item</font></div>
    </td>
    <td bgcolor="#990000" width="38%">
      <div align="center"><font color="#FFFFFF">Hidden Vendor &amp; Tracking</font></div>
    </td>
    <td bgcolor="#990000" width="33%">
      <div align="center"><font color="#FFFFFF">Misc</font></div>
    </td>
  </tr>
  <tr>
    <td bgcolor="#990000" width="29%">
      <textarea name="notes'.$totalitems.'" cols="50" rows="5" readonly>'.$_SESSION['notes'.$totalitems].'</textarea>
    </td>
    <td bgcolor="#990000" width="38%">
      <p><font color="#FFFFFF">Tracking # </font>
        <input type="text" name="tracking'.$totalitems.'"  value="'.$_SESSION['tracking'.$totalitems].'" readonly>
      </p>
      <p><font color="#FFFFFF">Vendorid #
        <input type="text" name="vendorid'.$totalitems.'"  value="'.$_SESSION['vendorid'.$totalitems].'" readonly>
        </font></p>
    </td>
    <td bgcolor="#990000" width="33%">
     <input type="hidden" name="removeitem" value="true">
    <input type="hidden" name="removeid" value='.$totalitems.'>
      <input type="submit" name="removeitem'.$totalitems.'" value="Remove Item">
    </td>
  </tr>
</table>
 </form>
';


         }



         }

0
Comment
Question by:aot2002
[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
1 Comment
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 12140883
A suggestion as to organize you're basket.

You could instead of doing your numbering yourself, have an array in your session:

$_SESSION['items'] = array(1 => 'data from item1', 2 => 'data from item2');

function additem would then be:

    function additem(){
        $itemdata = array();
        $itemdata['qty']  = $_REQUEST['qty'];
        $itemdata['interchangenumber']  = $_REQUEST['interchangenumber'];
        $itemdata['interchangeid']  = $_REQUEST['interchangeid'];
        $itemdata['description']  = $_REQUEST['description'];
        $itemdata['rate']  = $_REQUEST['rate'];
        $itemdata['amount']  = $_REQUEST['amount'];
        $itemdata['taxable']  = $_REQUEST['taxable'];
        $itemdata['notes']  = $_REQUEST['notes'];
        $itemdata['partid']  = $_REQUEST['partid'];
        $itemdata['tracking]  = $_REQUEST['tracking'];
        $itemdata['vendorid1']  = $_REQUEST['vendorid'];
       
        if(!isset($_SESSION['itemdata'])) $_SESSION['itemdata'] = array();
        if(!is_array($_SESSION['itemdata'])) $_SESSION['itemdata'] = array();
        $_SESSION['itemdata'][] = $itemdata; //add item to basket-array;
     }

You'd have to change your showallitems function, but for testing you could just use var_export of print_r;

regards

-r-
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 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