Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming > PHP Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-12-2009, 07:41 PM
  #1
Sawtooth500
Lord (Level 16)
 
Sawtooth500's Avatar
 
Join Date: Nov 2007
Location: Chicago, IL. USA
Posts: 574
iTrader: (0)
Sawtooth500 is on a distinguished road
Arrays in session vars mysteriously disappearing?

Ok, so go to http://dev.heatedblades.com/vehicles.php (fyi there is absolutely no PHP on this page).

Add a product to the cart, any product. The action page for the form is cart_add.php
Source for cart_add.php:
PHP Code:
<?php
session_start
();

switch(
$_GET['product']){
    case 
'complete_set':
        
$_SESSION[] = array(149.957.95'Heat Flexx Complete Set'$_GET['driver'], $_GET['passenger']); //1 is the quantity
    
break;
    case 
'single_blade':
        
$_SESSION[] = array(124.957.95'Heat Flexx Single Blade Only'$_GET['blade_size']);
    break;
    case 
'wiring_kit':
        
$_SESSION[] = array(16.954'Heat Flexx Wiring Kit Only');
    break;
}
echo 
print_r($_SESSION);
header("Location: ../cart.php");
?>
Ok, so as you can see with the print_r function the array populated correctly. The redirect to the cart page didn't work because of the print_r output, so hit back and click on "View Cart" in the navbar.

Source for cart.php:
PHP Code:
<?php
session_start
();
print_r($_SESSION);

switch(
$_POST['submit']){
    case 
'empty':
        
session_unset();
    break;
    case 
'update':
        for(
$i 1$i $_SESSION['cartnext']; ++$i){
            if(
$_SESSION[$i]){
                
$quant 'quantity' $i;
                if(
$_POST[$quant] != $_SESSION[$i][0] && is_numeric($_POST[$quant])) $_SESSION[$i][0] = number_format($_POST[$quant], 0);
                if(!
$_SESSION[$i][0] || $_POST['remove' $i]) unset($_SESSION[$i]);
            }
        }
    break;
    case 
'checkout':
        
header("Location: https://" $_SERVER['SERVER_NAME'] . "/customer_info.php");
        exit();
    break;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- InstanceBegin template="/Templates/main_template.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Heated Blades for Windshiled Wipers</title>
<!-- InstanceEndEditable -->
<link href="css/style.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
form {
    margin: 0px;
}
-->
</style>
<!-- InstanceEndEditable -->
</head>
<body onload="MM_preloadImages('images/nav-gradient-overlay.png');MM_preloadImages('/images/order_on.png')">
<div class="trackers">
  <script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
  <script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-11037093-1");
pageTracker._trackPageview();
} catch(err) {}</script>
  <noscript>
  <div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1031538361/?value=30.0&amp;label=bll_CI2iqwEQuY3w6wM&amp;guid=ON&amp;script=0"/> </div>
  </noscript>
</div>
<div class="mainstripe">
  <div class="container">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="images/heat-flexx-logo.png" width="310" height="175" alt="Heated Blades for Windshiled Wipers" /></td>
        <td><img src="images/blade-comparison.jpg" alt="Heat Flexx Blade Comparison" width="469" height="175" class="sideborder" /></td>
      </tr>
    </table>
  </div>
</div>
<div class="navstripe stripeborder">
  <div class="container blackback" align="center">
    <div class="nav-item" style="width:111px;""><a href="index.php">Home</a></div>
    <div class="nav-item"><a href="vehicles.php">Vehicle List</a></div>
    <div class="nav-item"><a href="instructions.php">Instructions</a></div>
    <div class="nav-item"><a href="contact.php">Contact</a></div>
    <div class="nav-item"><a href="resellers.php">Resellers</a></div>
    <div class="nav-item"><a href="/fleet.php">Fleet</a></div>
    <div class="nav-item" style="width:112px"><a href="/cart.php">View Cart</a></div>
    <div class="clear-both"></div>
  </div>
</div>
<div style="background-color:#FFFFFF">
  <div class="container">
    <div class="main"><!-- InstanceBeginEditable name="Main_Edit" -->
    <?php
    
if(!$_SESSION['cartnext']) echo '
      <div style="min-height:400px">
        <h1 align="center">Your cart is currently empty.</h1>
        <h2 align="center" style="margin-bottom:0px"><a href="/vehicles.php">Return to Vehicle List</a></h2>
      </div>'
;
    else { echo 
'
      <h1 align="center">HeatedBlades.com Shopping Cart</h1>
      <form action="" method="post" name="cartform">
        <table width="781" border="0" cellspacing="0" cellpadding="10">
          <tr class="header-text">
            <td align="center" width="461">Product</td>
            <td align="center" width="80">Quantity</td>
            <td align="center" width="80">Remove?</td>
            <td align="center" width="80">Price</td>
          </tr>'
;
          
$shipping 0;
          for(
$i 1$i $_SESSION['cartnext']; ++$i){
            if(
$_SESSION[$i]){
                echo 
'
                <tr>
                  <td>'
;
                if(
$_SESSION[$i][3] == 'Heat Flexx Complete Set' || $_SESSION[$i][3] == 'Heat Flexx Single Blade Only'){
                    echo 
'
                    <table width="461" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><strong>' 
$_SESSION[$i][3] . '</strong></td>
                      <td align="right">'
;
                    switch(
$_SESSION[$i][3]){
                        case 
'Heat Flexx Complete Set':
                        echo 
'Driver: ' $_SESSION[$i][4] . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Passenger: ' $_SESSION[$i][5];
                        break;
                        case 
'Heat Flexx Single Blade Only':
                        echo 
'Blade Size: ' $_SESSION[$i][4];
                        break;
                    }
                    echo 
'</td>
                    </tr>
                      </table>'
;
                }
                else {
                    echo 
'<strong>' $_SESSION[$i][3] . '</strong>';
                }
                echo 
'
                </td>
                <td align="center"><input name="quantity' 
$i '" type="text" size="2" maxlength="2" value="' $_SESSION[$i][0] . '" /></td>
                <td align="center"><input name="remove' 
$i '" type="checkbox" /></td>
                <td align="center">$' 
number_format($_SESSION[$i][1], 2) . '</td>
                  </tr>'
;
                
$shipping += $_SESSION[$i][2];
            }
          }
          echo 
'
          <tr class="header-text">
            <td align="right" colspan="3">Sub-Total:</td>
            <td></td>
          </tr>
          <tr>
            <td colspan="2"><em>*Illinois Residents will have 6.25% Sales Tax added at checkout.</em></td>
            <td align="right" style="font-size:large">Shipping:</td>
            <td style="font-size:large"></td>
          </tr>
          <tr class="header-text">
            <td align="right" colspan="3">Total:</td>
            <td></td>
          </tr>
          <tr>
            <td colspan="4" align="right"><table border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td><input value="checkout" name="submit" type="image" onmouseover="this.src=\'images/checkout_on.png\'" onmouseout="this.src=\'images/checkout_off.png\'" src="images/checkout_off.png" alt="Heated Blades" /></td>
                  <td width="20"></td>
                  <td><input value="empty" name="submit" type="image" onmouseover="this.src=\'images/empty_cart_on.png\'" onmouseout="this.src=\'images/empty_cart_off.png\'" src="images/empty_cart_off.png" alt="Heated Blades" /></td>
                  <td width="20"></td>
                  <td><input value="update" name="submit" type="image" onmouseover="this.src=\'images/update_cart_on.png\'" onmouseout="this.src=\'images/update_cart_off.png\'" src="images/update_cart_off.png" alt="Heated Blades" /></td>
                </tr>
              </table></td>
          </tr>
          <tr>
            <td colspan="4" align="center">If you want to add more blades for your other cars that are different lengths, <a href="/vehicles.php">return to the vehicles page</a> and add to cart again with your other blade sizes. Changing your quanity will get you more blades of the same sizes.</td>
          </tr>
        </table>
      </form>'
;
    }
      
?>
      <!-- InstanceEndEditable --></div>
    <div class="clear-both"></div>
  </div>
</div>
<div class="footerstripe stripeborder">
  <div class="container"> </div>
</div>
<div class="footstripe">
  <div class="container" align="center" style="font-weight:bold; font-size:small">
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="75">&copy;2009 HeatedBlades.com All Rights Reserved. </td>
      </tr>
    </table>
  </div>
</div>
</body>
<!-- InstanceEnd -->
</html>
So as you can see print_r is almost the first thing on this page. But the array I've stored in my session has magically disappeared! No matter what I try, the array always disappears. Why?
__________________
-Taras Hryniw

http://www.waltonstreetwebdesign.com
Sawtooth500 is online now   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-13-2009, 03:22 AM
  #2
Vege
Super Deity (Level 18)
 
Join Date: Sep 2004
Location: Finland
Posts: 3,410
iTrader: (0)
Vege is just really niceVege is just really niceVege is just really niceVege is just really nice
Sessions cannot have numeric (first level) keys.
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-13-2009, 03:49 AM
  #3
Sawtooth500
Lord (Level 16)
 
Sawtooth500's Avatar
 
Join Date: Nov 2007
Location: Chicago, IL. USA
Posts: 574
iTrader: (0)
Sawtooth500 is on a distinguished road
Thank you for clearing up a lot of frustration.
__________________
-Taras Hryniw

http://www.waltonstreetwebdesign.com
Sawtooth500 is online now   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 03:55 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.