Jump to content

SESSIONS Script and display


crazy8

Recommended Posts

Here is my sessions script I have writen up and I almost have all the bugs worked out but one.
[code]<?php
define("PHPINCDIR","../../phpinc/");
include ('ez_db.php');
require_once(PHPINCDIR.'ez_html_family.php');
require_once(PHPINCDIR.'ez_class_page.php');
require_once(PHPINCDIR."quotefunctions.php");
require_once(PHPINCDIR."html_common.php"); 

if (!empty($_POST['prod_quantity']) AND !empty($_POST['model'])){
    $_SESSION['prod_quantity'][$_POST['model']] = $_POST['prod_quantity'];

} elseif (!empty($_POST['cart_quantity'])){
    // update qty in cart session after submit
  for ($i=0; $i<count($_SESSION['prod_quantity']); $i++){
        if ($_POST['cart_quantity'][$i] >= 1){
            $_SESSION['prod_quantity'][$_POST['cart_id'][$i]] = $_POST['cart_quantity'][$i];
      } else {
            $_SESSION['prod_quantity'][$_POST['cart_id'][$i]] = '';
            unset($_SESSION['prod_quantity'][$_POST['cart_id'][$i]]);
        }
    }
}

if (is_array($_SESSION['prod_quantity'])){
    echo "<table width=\"600\" border=\"0\" cellspacing=\"0\" align=\"center\">";
    foreach ($_SESSION['prod_quantity'] AS $prod=>$qty){
    $sql = mysql_query("SELECT * FROM product WHERE model='$prod'");
    $row = mysql_fetch_array($sql);
    echo <<< TBL
        <tr><td class="plinky"><img src="i/t.gif" alt="" height="1" width="52"></td>
        <td align="center" class="plinky"><a href="ez_p.php?n={$row['id']}" target="_blank" onclick="javascript:op('ez_p.php?n={$row['id']}'); return false">{$row['model']}</a></td>
        <td align="center">{$row['little_desc']}</td>
        <td align="center" class="plinky"><input type="text" name="cart_quantity[]" value="$qty" style="width: 40px;" size="5" maxlength="5" class="quanw">
        <input type="hidden" name="cart_id[]" value="{$row['id']}"></td>
        </tr>
TBL;
}
echo "</table>";
}
?>[/code]
Now when I enter in a model number and a quantity and start to build a "list" of items, all is good. But as soon as I type "0" into one of the text boxes next to an item to clear the item from the list (I was able to do this at one time) I get this. Any Ideas what changes I need to make to my code to fix this?
[img]http://i2.photobucket.com/albums/y49/wayne3503/6.jpg[/img]
Link to comment
https://forums.phpfreaks.com/topic/36190-sessions-script-and-display/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.