error in sql

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
anmi
Forum Newbie
Posts: 1
Joined: Mon Dec 04, 2006 6:04 pm

error in sql

Post by anmi »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to create a shopping cart with three files a db.php, cart.php, and products.php. The only one that seems to work is db.php. When I run the cart.php I am receiving the following errors and I am not sure what it means:

Parse error: parse error, unexpected '<' in /afs/umbc.edu/users/a/n/andrade1/pub/www/is448/project6-1/cart.php on line 110

below is my code for cart.php:

Code: Select all

<?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");

$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");

$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
{
// 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; $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>
</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"]);

$totalCost = $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)
{

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

Lastly, ShowCart displays the total cost of all items in the users cart:

<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($totalCost, 2, ".", ","); ?></b>
</font>
</td>
</tr>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Please Edit your post, and put the [ php] [ /php] tags around your code, and specify what line 110 is.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$i <= 20
...
Post Reply