General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 14th, 2003, 08:26 PM
bmy78 bmy78 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 6 bmy78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Shopping Cart Tutorial Problem

Hello everyone.

I'm having problems with the shopping cart tutorial. I'm trying to adapt it to my own MySQL database, so things may look slightly different. When I click on "add to cart" and go to cart.php, everything seems fine. However, when I click on the dropdown tag to change the qty, the "Keep Shopping" block at the bottom duplicates itself. What gives? I think this may be an HTML parsing problem, where the function is calling the HTML code twice, since the function is being called twice, but how do I solve it?

Code below:
#CART.PHP

PHP Code:
[SIZE=1]<?php
session_start
();

setcookie("cart_id"session_id(), time() + ((3600 24) * 30));

?>

<html>
<head>
<title>Buy My Junk.com</title>
    
</head>

<body>
<table border="1" width="100%" cellspacing="0" cellpadding="0">
<tr>
    <!-- HEADER FOR LOGO, 468x60 BANNERS ----------------->
    <td colspan="3">
    <h1>Buy My Junk.com</h1>
    </td>
    </tr>
    <tr>
    <td colspan="2" align="right">
    LINK | LINK | LINK | LINK | LINK
    </td>
    <td align="right">
    <input type="text" size="10" value="Search">&nbsp;<input type="button" value="Go!"></td>
    </tr>
<tr>
    <!-- LEFT COLUMN FOR LINKS --------------------------->
    <td width="15%" valign="top">
    Register
        <!-- LOGIN TABLE --------------------------------->
        <table border="1" width="100%">
        <tr><td>Name: </td><td><input type="text" size="12" name="name"></td></tr>
        <tr><td>Pass: </td><td><input type="password" size="12" name="pass"></td></tr>
        <tr><td colspan="2"><input type="submit" name="login" value="Login"></td></tr>
        </table>
    
    LINK<br>
LINK<br>
LINK<br>
LINK<br>
LINK<br>
LINK<br>
LINK<br>
LINK<br>
LINK<br>
LINK<br>

    </td>
    
    <!-- CENTER COLUMN FOR TEXT, CONTENT ----------------->
    
    <td width="70%" valign="top">
    <h2>View Cart</h2>
    
    
        
            <?php
            
                
// includes
                
require("./data/functions.php");
                
                
// connect to db
                
db_connect();
                
                switch(
$_GET["action"])
                {
                    case 
"add_item":
                    {
                        
AddItem($_GET["id"], $_GET["qty"]);
                        
ShowCart();
                        break;
                    }
                    case 
"update_item":
                    {
                        
UpdateItem($_GET["id"], $_GET["qty"]);
                        
ShowCart();
                    }
                    case 
"remove_item":
                    {
                        
RemoveItem($_GET["id"]);
                        
ShowCart();
                        break;
                    }
                    default:
                    {
                        
ShowCart();
                    }
                }
                
                
                
                
            
?>
            
        
    <!-- RIGHT COLUMN FOR ADS ---------------------------->
    
    <td width="15%">
    &nbsp;
    </td>
</tr>
<tr>
    <!-- FOOTER FOR COPYRIGHT INFO ------------------------>
    <td colspan="3">&nbsp;</td>
</tr>
</table>




</td></tr>
</table>
</body>
</html>[/SIZE] 



AND HERE IS THE CODE FOR THE FUNCTION SHOWCART:



PHP Code:
function ShowCart()
{
    
$result mysql_query("select * from cart inner join products on cart.item_id = products.item_id where cart.cookie_id = '" GetCartId() . "' order by products.item_name asc")
        or 
mysql_error($result);
    
?>

    <script language="JavaScript">
        function UpdateQty(item)
        {
            item_id = item.name;
            newQty = item.options[item.selectedIndex].text;
            document.location.href='cart.php?action=update_ite  m&id='+item_id+'&qty='+newQty;
        }
    </script>

    <?php    

    
// once we've retrieved the list, each item is displayed as part of a table, as a table row
    
    
echo "<table border='1'>";
    
    while(
$row mysql_fetch_array($result))
    {
        
// increment the total cost of all items
        
        
$totalCost += ($row["qty"] * $row["item_price"]);
        
        
?>
         <tr><td width='15%' height='25'>
         <font face='verdana' size='1' color='black'>
         <select name="<?php echo $row['item_id']; ?>" onChange='UpdateQty(this)'>
        
        <?php
        
for ($i 1$i <= 20$i++)
        {
            echo 
"<option ";
            if (
$row["qty"] == $i)
            {
                echo 
" SELECTED ";
            }
            
            echo 
">" $i "</option>";
        }
        
        
?>
        </select></font></td>
        <td width='55%' height='25'>
        <font face='verdana' size='1' color='black'>
        <?php echo $row["item_name"]; ?>
        </font></td>
        <td width='20%' height='25'>
        <font face='verdana' size='1' color='black'>
        $ <?php echo number_format($row['item_price'], 2"."","); ?>
        </font></td>
        <td width='10%' height='25'>
        <font face='verdana' size='1' color='black'>
        <a href="cart.php?action=remove_item&id=<?php echo $row['item_id']; ?>">Remove</a>
        </font></td></tr>
    <?php
    
}
    
?>
    <tr><td width='100%' colspan='4'>
    <hr size='1' color='red' NOSHADE>
    </td></tr>
    <tr><td width='70%' colspan='2'>
    <font face='verdana' size='1' color='black'>
    <a href='products.php'><< Keep Shopping</a>
    </font></td>
    <td width='30%' colspan='2'>
    <font face='verdana' size='2' color='black'>
    <b>Total: <?php echo number_format($totalCost2"."","); ?></b>
    </font></td></tr>
    </table>
    <?php
    





I would appreciate any help you can give me.

Thanks.

--Brian

Reply With Quote
  #2  
Old July 14th, 2003, 09:06 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Brian,

Do you have a live copy up to see exactly what's happening?

I'm looking through the code, and can't seem to find where the problem lies... It may be a simple error that I'm overlooking.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Shopping Cart Tutorial Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT