-1

I am getting this error in my cart.php

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in cart.php on line 74

line 74 is

$subtotal = $_SESSION['cart'][$row['id_number']]['quantity']*$row['price'];



<?php

if(isset($_POST['submit']))
{
    foreach($_POST as $items => $item)
    {
        $items = explode("-",$items);
        $items = end($items);
        $items = explode("submit",$items);
        $items = end($items);

        if($_POST['quantity-'.$items]<=0)
        {
            unset($_SESSION['cart'][$items]);
        }

        else
        {
            $_SESSION['cart'][$items]['quantity']=$item;
        }
    }
}   error_reporting(0);

?>

<h1>View Cart</h1>

<a href = "cds.php?page=products" title="go back to products page">Go Back To Products Page</a>

<?php $sql = "SELECT * FROM product WHERE id_number IN (";
    foreach($_SESSION['cart'] as $id_b00073643 => $value)
    {
        $sql.= $id_b00073643.",";
    }

        $sql= substr($sql,0,-1).") ORDER BY name ASC";
        $query = mysql_query($sql);

    if(empty($query))
    {
        echo"You need to add an item first";
    }
?>

    <form method = "post" action = "cds.php?page=cart">
    <fieldset>

                <table border="1">
                <tr>
                    <th>artist</th>
                    <th>name</th>
                    <th>price</th>
                    <th>genre</th>
                    <th>type</th>
                    <th></th>
                </tr>

    <?PHP

    $sql = "SELECT * FROM product WHERE id_number IN (";
    foreach($_SESSION['cart'] as $id_b00073643 => $value)
    {
            $sql.= $id_b00073643.",";
        }

            $sql= substr($sql,0,-1).") ORDER BY artist ASC";
            $query = mysql_query($sql);
            $cost = 0;

            if(!empty($query))`
            {
                while($row = mysql_fetch_array($query))
                {
                    $subtotal = $_SESSION['cart'][$row['id_number']]['quantity']*$row['price'];
                    $cost += subtotal;


                    ?>

                    <tr>
                        <td><?PHP echo $row['name'];?></td>
                        <td><input type = "text" name = "quantity"<?PHP echo $row['id_number'];?>"size ="5" value="<?php echo $_SESSION['cart'][$row['id_number']]['quantity'];?>"/></td>
                        <td><?php echo"$".$row['price'];?></td>
                        <td><?php echo"$".$_SESSION['cart'][$row['id_number']]['quantity']*$row['price'];?></td>
                    </tr>

            <?PHP

            } }
            ?>

            <tr>

            <td> </td>
            <td></td>
            <td>total price</td>
            <td><?PHP echo"$" . $cost; ?></td>
            </tr>
            </table>

            <input type = "submit" name = "submit" value = "update cart"/></fieldset>
            </form>
            <p> to remove an item set quantity to 0</p>
AnonymousAlias
  • 1,149
  • 2
  • 27
  • 68

1 Answers1

0

Not sure it is your no 74 line or not but Why you are using backtick (`)? Make a try after removing it.

on  if(!empty($query))`
                     ^^ 
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
  • Ive been looking at that for the past hour and didnt spot that.cheers! – AnonymousAlias Apr 22 '15 at 17:26
  • do you see anything wrong with this line? if($_POST['quantity-'.$items]<=0) { unset($_SESSION['cart'][$items]); } I am getting the error "Undefined index: quantity-quantity" – AnonymousAlias Apr 22 '15 at 17:48
  • @ Mick O'Gorman ,Try to set this to a variable & then check with isset() like this `$quantity=$_POST['quantity-'.$items]; if(isset($quantity) && ($quantity<=0)){........}` – A l w a y s S u n n y Apr 22 '15 at 18:53
  • Nothings working at all anymore for some reason i didnt think i even changed anything but nothing will work getting stressed out :/ do you think you could take a look at my code here http://stackoverflow.com/questions/29806676/php-telling-me-i-have-an-error-in-sql-syntax-but-dont-help-appreciated ?? – AnonymousAlias Apr 22 '15 at 19:07