Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 11-21-2007, 09:16 AM PHP Cart Help!
Novice Talker

Posts: 9
Trades: 0
Okay, I have a cart script but for some reason it won't add the item to the cart. Every time I click Add Item To Cart it takes me to the cart and says I have nothing in it! Please help me!

Cart.php

PHP Code:
<?
    
include("common.php");
    require_once(
"templates/HeaderTemplate.php");
    switch (
$a){
        case 
"add":
            
AddItem($_GET["item"],1);
            
$totalCost ShowCart();
            break;
        case 
"update":
            
$myqty $_REQUEST['qty'];
            while(list(
$k,$v) = each($_REQUEST[ids])){
                
$qty $myqty[$k];
                if( 
$qty == ){
                    
RemoveItem($v);
                }else{
                    
UpdateItem($v$qty);
                }
            }
            
$totalCost ShowCart();
            break;
        case 
"remove":
            
RemoveItem($_GET["item"]);
            
$totalCost ShowCart();
            break;
        default:
            
$totalCost ShowCart();
            break;
    }
    require_once(
"templates/FooterTemplate.php");
    
    function 
AddItem($item,$qty=1){
        
//get the product info
        
$q1 "select * from items where ItemID = '$item' ";
        
$r1 mysql_query($q1) or die(mysql_error());
        
$a1 mysql_fetch_array($r1);
        
//add to cart
        
$chk mysql_query("SELECT * FROM cart WHERE OrderID='".GetCartId()."' AND ItemID='$a1[ItemID]'");
        if( 
mysql_num_rows($chk) > ){
            
UpdateItem($item,2);
        }else{
            
$q2 "insert into cart set 
                                        OrderID = '"
.GetCartId()."',
                                        ItemID = '
$a1[ItemID]',
                                        ItemPrice = '
$a1[ItemPrice]',
                                        ItemQty = '
$qty',
                                        ItemTotal = '
$a1[ItemPrice]' ";
            
mysql_query($q2) or die(mysql_error());
        }
    }
    function 
UpdateItem($item,$qty){
        
//get the product info
        
$q1 "select * from items where ItemID = '$item' ";
        
$r1 mysql_query($q1) or die(mysql_error());
        
$a1 mysql_fetch_array($r1);

        
//add to cart
        
$q2 "UPDATE cart SET ItemQty = '$qty' WHERE OrderID = '".GetCartId()."' AND ItemID = '$a1[ItemID]'";
        
mysql_query($q2) or die(mysql_error());
    }
    function 
RemoveItem($item){
        
mysql_query("DELETE FROM cart WHERE OrderID= '" GetCartId() . "' and ItemID = '$item'");
    }
    function 
ShowCart(){
        
//get the cart content
        
$q1 "select * from cart, items where cart.OrderID = '".GetCartId()."' and cart.ItemID = items.ItemID order by items.ItemName";
        
$r1 mysql_query($q1) or die(mysql_error());
        if(
mysql_num_rows($r1) == '0'){
            include_once(
"templates/EmptyCartTemplate.php");
        }else{
            
$col "white";
            while(
$a1 mysql_fetch_array($r1)){
                if(
$col == "white"){
                    
$col "dddddd";
                }else{
                    
$col "white";
                }
                
$a1[ItemTotal] = ( $a1[ItemPrice] * $a1[ItemQty] );
                
$rows .= "<tr bgcolor=\"$col\">\n\t<td class=BlackLink>$a1[ItemName]</td>\n<td align=right>$aset[currency_sign] $a1[ItemPrice]</td>\t\n\t<td align=center>\n\t\t<input type=text size=3 name=\"qty[]\" value=\"$a1[ItemQty]\">\n\t\t<input type=hidden name=\"ids[]\" value=\"$a1[ItemID]\">\n\t</td>\n\t<td align=right>$aset[currency_sign] $a1[ItemTotal]</td>\n</tr>\n\n";
                
$order_total $order_total + ( $a1[ItemPrice] * $a1[ItemQty] );
            }
            
$order_total number_format($order_total2"."",");
            include_once(
"templates/ViewCartTemplate.php");
        }
    }
?>

ViewItemTemplate.php

PHP Code:
<br>

<table align=center width=400 border=0>
  <tr> 
    <td width="250" valign=top> <span class=ItemTitle> 
      <?=$a1[ItemName]?>
      </span><br>
<br>
      <a class=CategoryName href="categories.php?CategoryID=<?=$a1[ItemCategory]?>"> 
      <?=$a1[CategoryName]?>
      </a><br> <br>
      <span class=PriceClass><strong>Price:</strong> 
      <?=$aset[currency_sign]?>
      <?=$a1[ItemPrice]?>
      </span> <br>
      <p><br>
        <strong>Demo:</strong> <strong> 
        <?    if(($a1[Demo]) == 1){    ?>
        <a href="<?=$a1[DemoURL]?>" target=_blank> 
        <?=$a1[DemoURL]?>
        </a> </STRONG><font size="1"><BR>
        (Will open in a new window)</font> 
        <?    }else{    ?>
        <STRONG><font color="#FF0000">No demo available</font> 
        <?    }    ?>
        </strong></p>
      <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td class=ItemDesc> 
      <?=nl2br($a1[ItemDesc]);?>
    <p>&nbsp;</p></td>
  </tr>
  <tr> 
    <td width=400 class=ItemDesc><table width="391" border="0" cellspacing="0" cellpadding="0">
        <tr> 

            <!-- ADD TO CART BUTTON -->
          <td width="133"><div align="center"><a href="cart.php?a=add&item=<?=$a1[ItemID]?>"><img src="images/addcart.gif" width="116" height=21 alt="Add to cart" border=0></a></div></td>
            <!-- END ADD TO CART BUTTON -->

          <td width="133"><div align="center"><a href="cart.php"><img src="images/viewcart.gif" width="116" height=21 alt="View cart" border=0></a></div></td>
        </tr>
      </table></td>
  </tr>
</table>
Stealth is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-21-2007, 10:28 AM Re: PHP Cart Help!
metho's Avatar
Ultra Talker

Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
Trades: 0
include

ini_set('display_errors','On');

at the top of commpn.php. Post any warnings and notices. There's a bunch of places where stuff can be going wrong, error display will help.
__________________
I do
Please login or register to view this content. Registration is FREE
based.
Spend a lot of time in
Please login or register to view this content. Registration is FREE
.
And
Please login or register to view this content. Registration is FREE
chews up the rest.
metho is offline
Reply With Quote
View Public Profile Visit metho's homepage!
 
Old 11-21-2007, 01:31 PM Re: PHP Cart Help!
Novice Talker

Posts: 9
Trades: 0
Okay, I will try that.

Thanks.
Stealth is offline
Reply With Quote
View Public Profile
 
Old 11-21-2007, 02:20 PM Re: PHP Cart Help!
Novice Talker

Posts: 9
Trades: 0
Still doesn't work! I looked over my common.php too. Please if anyone can help! (btw sorry for the double post)
Stealth is offline
Reply With Quote
View Public Profile
 
Old 11-22-2007, 06:44 AM Re: PHP Cart Help!
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
What exactly does not work as you expect?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 11-22-2007, 08:16 AM Re: PHP Cart Help!
ericajoieake's Avatar
Super Talker

Posts: 125
Trades: 0
I'm so thankful to found this forum, and thanks also for these infomation!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
ericajoieake is offline
Reply With Quote
View Public Profile Visit ericajoieake's homepage!
 
Old 11-22-2007, 09:41 AM Re: PHP Cart Help!
Novice Talker

Posts: 9
Trades: 0
When I click add to cart it takes me to the cart and says I have nothing in it.
My add to cart URL is /cart.php?a=add&item=<?$a1=[ItemID]?>
Which with my test item it would look like this -
/cart.php?a=add&item=88
Stealth is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Cart Help!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.62392 seconds with 12 queries