hey, i've been having some trouble with the devolopment of a shopping cart to use on my site. it says there is a parse error on the last line, but i've went through the entire script and couldn't find the problem. thanks for the help in advance.
<?php
session_start();
$connect=mysql_connect("localhost", "$username", "$pass");
mysql_select_db("$db", $connect);
function make_user_id($length, $strength=0) {
if(isset($_SESSION["user_id"]))
{
$user_id = $_SESSION["user_id"];
}
else
{
$vowels = 'aeiouy';
$consonants = 'bdghjlmnpqrstvwxz';
if ($strength & 1)
{
$consonants .= 'BDGHJLMNPQRSTVWXZ';
}
if ($strength & 2)
{
$vowels .= "AEIOUY";
}
if ($strength & 4)
{
$consonants .= '0123456789';
}
if ($strength & 8)
{
$consonants .= '@#$%^';
}
$user_id = '';
$alt = time() % 2;
srand(time());
for ($i = 0; $i < $length; $i++) {
if ($alt == 1)
{
$user_id .= $consonants[(rand() % strlen($consonants))];
$alt = 0;
}
else
{
$user_id .= $vowels[(rand() % strlen($vowels))];
$alt = 1;
}
}
return $user_id;
session_register('user_id');
$_SESSION['user_id'] = $user_id;
}
}
switch($action){
case "add":
{
add($_GET["id"], $_GET["qty"]);
showcart();
break;
}
case "update":
{
update($itemid, $itemqty);
showcart();
break;
}
case "remove":
{
remove($itemid);
showcart();
break;
}
default:
{
showcart();
}
}
function add($itemid, $itemqty)
{
$sql = mysql_query("SELECT * FROM cart WHERE
userid='" . make_user_id() . "' AND id='$itemqty'");
$row = mysql_fetch_array($sql);
$numrows = $row[0];
if($numRows == 0)
{
mysql_query("INSERT INTO cart(cookieId, itemId, qty, itemPrice)
VALUES('" . make_user_id() . "', $id, $itemqty, $price)");
}
else
{
update($itemid, $itemqty);
}
function update($itemid, $itemqty)
{
if($itemqty == 0)
{
remove($itemId);
}
elseif($itemqty > $qty)
{
$result = 'We\'re sorry, but we only have $qty of the item
you requested<br>';
}
else
{
mysql_query("UPDATE cart SET qty=$itemqty
WHERE cookieId='" . make_user_id() . "' AND itemId=$itemid");
}
}
function remove($itemid)
{
mysql_query("DELETE FROM cart WHERE cookieId='" . make_user_id() . "'
AND itemId=itemId");
}
function showcart()
{
$totalCost = 0;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?php echo "$title"; ?></title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><?php include 'top.php'; ?> </td>
</tr>
<tr>
<td width="161"><?php include 'side.php'; ?> </td>
<td><div align="center"><?php echo '$result'; ?><?php echo '$result2'; ?>
<?php echo '$result3'; ?>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000066">
<tr>
<td width="15%" height="25" bgcolor="#000099"> <font face="verdana" size="1" color="white">
<b>Qty</b> </font> </td>
<td width="55%" height="25" bgcolor="#000099"> <font face="verdana" size="1" color="white">
<b>Product</b> </font> </td>
<td width="20%" height="25" bgcolor="#000099"> <font face="verdana" size="1" color="white">
<b>Price </b></font> </td>
<td width="10%" height="25" bgcolor="#000099"> <font face="verdana" size="1" color="white">
<b>Remove?</b> </font> </td>
</tr>
<?php
$query = "select * from cart where cookieId='" . make_user_id() . "' order by
itemId desc";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$totalCost += ($row["qty"] * $row["itemPrice"]);
?>
<tr>
<td width="15%" height="24"> <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>
<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
}
?>
<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>
</table>
</form>
</p>
</body>
</html>