PHP Parse error: parse error, unexpected $end in C:\test\kelly.php on line 118

<?php

function AddItem($itemId, $qty){

$db=new mysqli('localhost','root','','test');
$db->select_db('test');
$query="select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId";
$result=$db->query($query);

$row =$result->fetch_assoc();
$numRows = $row[0];
if($numRows == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query
$query="insert into cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)";
$result=$db->query($query);
}
else
{
// This item already exists in the users cart,
// we will update it instead
UpdateItem($itemId, $qty);
}
}

function UpdateItem($itemId, $qty){
$query="update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId";
$result=$db->query($query);
}
function RemoveItem($itemId){
$query="delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId";
$result=$db->query($query);
}


function ShowCart(){


$query="select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc";
$result=$db->query($query);
while($row = $result->fetch_assoc())
{
// 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>
<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>
<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">&lt;&lt; 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>

What's line 118?

Check for matching quotation marks and matching braces. Something should be closed or ended that is not.

Either you didn't give us the entire script or something is very wrong...

Either way, I changed a few things with what you did post and here's what I've got.

<?php

function AddItem($itemId, $qty){

    $db=new mysqli('localhost','root','','test');
    $db->select_db('test');
    $query="select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId";
    $result=$db->query($query);

    $row =$result->fetch_assoc();
    $numRows = $row[0];
    if($numRows == 0)
        {
        // This item doesn't exist in the users cart,
        // we will add it with an insert query
        $query="insert into cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)";
        $result=$db->query($query);
    }
    else
    {
        // This item already exists in the users cart,
        // we will update it instead
        UpdateItem($itemId, $qty);
    }
}

function UpdateItem($itemId, $qty){
    $query="update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId";
    $result=$db->query($query);
}
function RemoveItem($itemId){
    $query="delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId";
    $result=$db->query($query);
}


function ShowCart(){

    $query="select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc";
    $result=$db->query($query);
    while($row = $result->fetch_assoc())
    {
    // Increment the total cost of all items
    $totalCost += ($row["qty"] * $row["itemPrice"]);
    echo '    <tr>
     <td width="15%" height="25">
     <font face="verdana" size="1" color="black">
     <select name="'. $row["itemId"] .'" onChange="UpdateQty(this)">';
     
    for($i = 1; $i <= 20; $i++)
    {
        echo "<option ";
        if($row["qty"] == $i)
        {
            echo " SELECTED ";
        }
        echo ">" . $i . "</option>";
    }
echo '
</select>
</font>
</td>
<td width="55%" height="25">
<font face="verdana" size="1" color="black">
'. $row["itemName"] .'
</font>
</td>
<td width="20%" height="25">
<font face="verdana" size="1" color="black">
$'. 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='. $row["itemId"] .'">Remove</a>
</font>
</td>
</tr>
<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">&lt;&lt; Keep Shopping</a>
</font>
</td>
<td width="30%" colspan="2">
<font face="verdana" size="2" color="black">
<b>Total: $'. number_format($totalCost, 2, ".", ",") .'</b>
</font>
</td>
</tr>';
    }
}
This article has been dead for over six months. Start a new discussion instead.