SESSION help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazy8
Forum Commoner
Posts: 29
Joined: Fri Dec 22, 2006 12:19 pm

SESSION help

Post by crazy8 »

Well I have returned back once again in need of a little help. Ill try to explain this as quick but as clear as I can. Ok so here we go. I am working on a project for a corporate website for the company I work for. There are pretty much two pages involved. A customer will come to "page 1" and enter in a model number and quantity then hit the "update quote" button or just hit Enter. When they do that it gets added to a "list" type cart if you will. Now once they are done with the quote they can do one of two things. Either they can hit "Clear Quote" or "Get Quote" which will take them to "Page 2" to fill out some info and also on the bottom of page two also shows a list of everything in their quote.

Now here are my issues I am having. Granted this wouldnt be "typical" behavior of a regular customer but still they need to be fixed non the less.

1) After a quote gets built and "Clear Quote" is pressed, the cart on "Page 1" is cleared but if you decided to hit "Get Quote" after you press "Clear Quote" all of the items that should have been cleared will appear on "Page 2"

2) When an item gets added to the "list" the quantity shows up in the list, inside a text box so that the quantity can be changed by the customer if needed. Now If I build a quote then change ALL quantities to "0" they all do clear from the list after I hit "Enter" or "Update Quote" but again if I chose to hit "Get Quote" after I will be sent to "Page 2" and ALL of the items that should have been cleared will appear at the bottom of the page instead of being cleared.

So those are the last two bugs I need to somehow correct I have gone over many methods of trying to fix this without much luck. I have been told all the code works and that it may be server related issues causing all this trouble. So I guess what Im hoping for is either verification that the code does work or that something is wrong in my code.

Thank you much for the help and her is all my code as of now.

Code: Select all

<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>EZ Quote</title>
<script type="text/javascript" language="JavaScript">
<!-- Hide script from some browsers
        function op(link) { var newWindow = window.open(link, 'prod_page','width=480,height=540,resizable,scrollbars,top=0,left=0,screenY=0,screenX=0'); newWindow.focus( ); }
        // end script hiding from some browsers -->
</script><script type="text/javascript" src="js/startlist.js"></script>
<link rel="stylesheet" href="styleNN.css" type="text/css">
<style type="text/css" title="currentStyle" media="all">
@import "/css/global.css";
@import "/css/secondary.css";
@import "/css/resources.css";
@import url(style.css); /*IE and NN6x styles*/a#logo{background-image:url(img/quote/winsted_logo.gif);}
</style>
<link rel="Shortcut Icon" type="image/x-icon" href="/favicon.ico">
</head>
<body id="winsted-body" onload="document.forms[0].model.focus()">
<div id="container">
    <div id="headerSection"><a id="logo" href="/index.htm"><span>Winsted</span></a>

        <div id="tagLine">
            <p>Setting the Standard in Technical Furniture Systems</p>
        </div>
        <div id="search">
            <a href="quote.php" class="goButton">quote generator </a><a href="catalog.htm" class="goButton">catalog request </a>
        </div>
        <ul id="nav">

            <li class="firstChild"><a href="/product.htm">PRODUCTS</a>
                <ul>
                    <li><a href="/cmd2.htm">Command Consoles</a></li>
                    <li><a href="http://www.techinteriors.com/">Custom Manufacturing</a></li>
                    <li><a href="/lcd3.htm">LCD/3 Consoles</a></li>
                    <li><a href="/video.htm">Video Consoles</a></li>

                    <li><a href="/security.htm">Security Consoles</a></li>
                    <li><a href="/secprod.htm">Compact Security Products</a></li>
                    <li><a href="/vracks.htm">Equipment Racks</a></li>
                    <li><a href="/multi.htm">Multimedia Desks</a></li>
                    <li><a href="/cart.htm">Audio/Visual Carts</a></li>
                    <li><a href="/tape.htm">Tape Storage</a></li>

                    <li><a href="/static/winstedcustom.htm">Winsted Custom</a></li>
                </ul>
            </li>
            <li><a href="/sites.htm">MARKETS</a>
                <ul>
                    <li><a href="/airport.htm">Airports</a></li>
                    <li><a href="/casino.htm">Casinos</a></li>

                    <li><a href="/control.htm">Control Rooms</a></li>
                    <li><a href="/corpsec.htm">Surveillance</a></li>
                    <li><a href="/NOC.htm">Network Operations Centers</a></li>
                    <li><a href="/power.htm">Power Plants</a></li>
                    <li><a href="/prison.htm">Prisons</a></li>
                    <li><a href="/production.htm">Production</a></li>

                    <li><a href="/school.htm">Schools</a></li>
                    <li><a href="/tape-install.htm">Tape Storage</a></li>
                    <li><a href="/transport.htm">Transportation</a></li>
                </ul>
            </li>
            <li><a href="/resources.htm">RESOURCES</a>
                <ul>

                    <li><a href="/onlinecat/t1.html">Online Catalog</a></li>
                    <li><a href="/quote.php">Quote Generator</a></li>
                    <li><a href="/catalog.htm">Request a Free Catalog</a></li>
                    <li><a href="/ae/index.htm">A & E Specs</a></li>
                    <li><a href="/literature.htm">Literature</a></li>

                    <li><a href="/tradeshows.htm">Trade Shows</a></li>
                    <li><a href="/news.htm">News / Press</a></li>
                    <!-- <li><a href="/signup.htm">Newsletters</a></li>  -->
                    <li><a href="/sitemap.htm">Sitemap</a></li>
                </ul>
            </li>
            <li><a href="/soft.htm">DESIGN SOFTWARE</a>

                <ul>
                    <li><a href="/soft.htm">WELS Design Software</a></li>
                    <li><a href="/wels.php">Request a Free Copy</a></li>
                </ul>
            </li>
            <li><a href="/contact.htm">CONTACT US</a>
                <ul>

                    <li><a href="/contact.htm">Contacts</a></li>
                    <li><a href="/profile.htm">Company Profile</a></li>
                    <li><a href="/testimonials.htm">Testimonials</a></li>
                    <li><a href="/privacy.htm">Privacy Disclosure</a></li>
                    <li><a href="/dealer.htm">Dealers Corner</a></li>
                </ul>

            </li>
        </ul></div>
    <div>
    <div id="quote_outer">
    <div id="quote_inner">
    
    <div class="desc"><p align="center"><strong>Enter model numbers and desired quantities<br>of products for your quote.</strong></p></div>
    <form name="cart_quantity" action="ez_quote.php" method="POST" style="display:inline; margin:0px;" autocomplete = "off">
    
<?
//This gives you the ability to delete all the contents in the cart.
if ($_POST['del_x']){
unset($_SESSION['prod_quantity_cart']);
unset($_SESSION['prod_quantity']);
}
?>

<div class="bttns">
<input type="image" src="i/update_quote.gif" border="0" alt="Update Totals">
<A HREF="quote_sess.php"><IMG src="i/get_quote.gif" border="0"></A>
<input type="image" name="del" src="i/clear_quote.gif">
</div>
<a name="quote"></a><div class="h2brdr"><h2>Current Quote</h2></div>

<?php
include ('ez_db.php');

//This will validate the model number typed in by the customer to make sure it exists in the db.
//If model does exist in db then item and its corisponding info will be displayed into cart.
//If model doesnt exist in db then nothing is displayed.
if($rec=mysql_fetch_array(mysql_query("SELECT * FROM product WHERE model= '$model'"))){
    if($rec['model']==$model){
        //Building our session here.
        if (!empty($_POST['prod_quantity']) AND !empty($_POST['model'])){
    $_SESSION['prod_quantity_cart'][$_POST['model']] = $_POST['prod_quantity'];
		}
	}
} elseif (!empty($_POST['cart_quantity'])){

    while (list ($id,$qty) = each($_POST['cart_quantity'])){
        //echo "$id=>$qty<br />";
        // update qty in cart session after submit
        if ($qty < 1){
            $_SESSION['prod_quantity_cart'][$id] = '';
            unset($_SESSION['prod_quantity_cart'][$id]);
        }
        unset($_SESSION['prod_quantity']);
    }
}
//This will connect to the database and grab the data that we need and display everything accordingly.
if (is_array($_SESSION['prod_quantity_cart'])){
    echo "<table width=\"600\" border=\"0\" cellspacing=\"0\" align=\"center\">";
    foreach ($_SESSION['prod_quantity_cart'] AS $prod=>$qty){
    $_SESSION['prod_quantity'][$row['id']] = $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">$prod</a></td>
        <td align="center">{$row['little_desc']}</td>
        <td align="center" class="plinky"><input type="text" name="cart_quantity[$prod]" value="$qty" style="width: 40px;" size="5" maxlength="5" class="quanw">
        <input type="hidden" name="cart_id[]" value="{$prod}"></td>
        </tr>
TBL;
}
echo "</table>"; 
}
?>
  
  <table style="table-layout:fixed" width="600" height="20" border="0" align="center" cellspacing="0">
<tr>
<td align="right" width="104" class="plinky"><strong>Model #:</strong></td>
<td class="plinky" align="center" width="71"><input name="model" style="width: 40px;" size="7" maxlength="7" class="plinky" value="" type="text"></td>
  <td colspan="2" width="416" align="left" class="plinky"><strong>Quantity:</strong>
    <input name="prod_quantity" size="2" maxlength="6" class="plinky" type="text" style="width: 40px">
  </td>
</tr></table>
    </form></div>
    </div>
        <div id="divider"></div>
        <div id="footerSection">
<p>
                <a href="/product.htm">products</a> :
                <a href="/sites.htm">markets</a> :
                <a href="/resources.htm">resources</a> :
                <a href="/soft.htm">design software</a> :
                <a href="/contact.htm">contact us</a> :
                <a href="/sitemap.htm">sitemap</a> :
                <a href="/catalog.htm">catalog request</a> :
                <a href="/dealer.htm">dealers' corner</a>

          </p>
            <p>
                &copy; 2005 Winsted Corporation
            </p></div>
    </div><!-- /contentSection -->
</div><!-- /container -->
</body>
</html>
Post Reply