我在cart.php中收到此错误
解析错误:语法错误,意外''(T_ENCAPSED_AND_WHITESPACE),期望标识符(T_STRING)或变量(T_VARIABLE)或数字(T_NUM_STRING)在第74行的cart.php中
第74行
$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>
答案 0 :(得分:0)
不确定这是否是你的74行但你为什么使用反引号(`)?删除后试一试。
on if(!empty($query))`
^^