MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 29th, 2004, 03:05 PM
jude jude is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Portsmouth, UK
Posts: 4 jude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to jude
Unhappy Shopping cart parse error

Hi,


I'm new to php and mysql and am having problems using the shopping cart script.I have got the products.php to work but get an error when I try to add an item or display the shopping cart.

The error I'm getting is Parse error: parse error, expecting `'{'' in xxx/www/cart.php on line 29
Here is my cart.php script:

PHP Code:
<?php

include("db.php");

switch(
$_GET["action"])

{

case 
"add_item":

{

AddItem($_GET["id"], $_GET["qty"]);

ShowCart();

break;

}

case 
"update_item":

{

UpdateItem($_GET["id"], $_GET["qty"]);

ShowCart();

break;

}

case 
"remove_item":

{

RemoveItem($_GET["id"]);

ShowCart();

break;

}

default:

{

ShowCart();

}

}

function 
AddItem($itemId$qty)

$result mysql_query("select count(*) from cart where cookieId = '" GetCartId() . "' and

itemId = $itemId"
);

$row mysql_fetch_row($result);

$numRows $row[0];

if(
$numRows == 0)

{

// This item doesn't exist in the users cart,

// we will add it with an insert query

@mysql_query("insert into cart(cookieId, itemId, qty) values('" GetCartId() . "', $itemId,

$qty)"
);

}

else

{

// This item already exists in the users cart,

// we will update it instead

UpdateItem($itemId$qty);

}

function 
UpdateItem($itemId$qty)

mysql_query("update cart set qty = $qty where cookieId = '{" GetCartId() . "}' and itemId =

$itemId"
);

function 
RemoveItem($itemId)

mysql_query("delete from cart where cookieId = '" GetCartId() . "' and itemId = $itemId");

function 
ShowCart()

$result mysql_query("select * from cart inner join items on cart.itemId = items.itemId

where cart.cookieId = '" 
GetCartId() . "' order by items.itemName asc");

while(
$row mysql_fetch_array($result))

{

// Increment the total cost of all items

$totalCost += ($row["qty"] * $row["itemPrice"]);

?>

<tr>

<td width="15%" height="25">

<font face="verdana" size="1" color="black">

<select name="<?php echo $row["itemId"]; ?>" onChange="UpdateQty(this)">

<?php

for($i 1;

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["itemName"]; ?>

</font>

</td>

<td width="20%" height="25">

<font face="verdana" size="1" color="black">

$<?php echo number_format($row["itemPrice"], 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["itemId"]; ?>">Remove</a>

</font>

</td>

</tr>

<?php

}

// Increment the total cost of all items

$totalCost += ($row["qty"] * $row["itemPrice"]);

<
select name="<?php echo $row["itemId"]; ?>" onChange="UpdateQty(this)">

<?
php

for($i 1$i <= 20$i++)

{

echo 
"<option ";

if(
$row["qty"] == $i)

{

echo 
" SELECTED ";

}

echo 
">" $i "</option>";

}

?>

</select>

<script language="JavaScript">

function UpdateQty(item)

{

itemId = item.name;

newQty = item.options[item.selectedIndex].text;

document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty;

}

</script>

cart.php?action=update_item&id=5&qty=4

<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>
<?php ?>

</table>

</html>




Would really appreciate any help
Thanks
Jude

Reply With Quote
  #2  
Old June 29th, 2004, 07:41 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Which line is 29?
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old June 30th, 2004, 02:49 PM
jude jude is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Portsmouth, UK
Posts: 4 jude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to jude
Line 29

Think line 29 is this:

PHP Code:
 $result mysql_query("select count(*) from cart 
where cookieId = '" 
GetCartId() . "' and itemId = $itemId"); 


Thanks
Jude

Reply With Quote
  #4  
Old June 30th, 2004, 02:54 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
Hey Jude,

I'm not sure if maybe the forum software stripped them out (can't see why it would), but you don't have any opening or closing { } for your functions. You seem to have an awful lot for your switch/case statement (I don't think you need braces for your case statements... As long as you end the case with a "break" statement, you don't need them.

As for the error message, try adding { } around your functions, and that should resolve the issue.

HTH!
__________________
____________________________________________
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
  #5  
Old June 30th, 2004, 04:20 PM
jude jude is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Portsmouth, UK
Posts: 4 jude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to jude
Thanks Frank, tried that & am now getting
Parse error: parse error, expecting `';'' in xxx/www/cart.php on line 68

This is line 68:


PHP Code:
for($i 1$i <= 20$i++);; 



This code was all taken direct from the shopping cart tutorial, has anyone got a fully working version of this? Would also like any code I could add (assuming I get this working !) to enable the full cart, i.e. checkout, customer info, selecting payment type, shipping method & then sending details to PayPal.

Thanks again
Jude

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Shopping cart parse error


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