I'm getting an error with my code.
Error Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\phpcart5\products.php on line 41.
Is it an error of brackets or because of the while loop? Can someone please help?
<?php session_start();?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Shoping Cart </title>
<!-- This page is for displaying the products -->
</head>
<body bgcolor="#000000">
<div align="center">
<h3 style="background-color:#FF0">Products</h3>
<a style="color:#FFFF00; text-decoration:none" href="cart.php?action=none"><span style="margin-left:500px;">
<img src="online/images/cart.png">Cart (<? echo count($_SESSION['cart']); ?>
)</span></a>
</br>
<table border="0" bgcolor="#f6f6f6" cellpadding="0px" width="600px">
<?php
//Fetching the product details from database
include("common/db.php");
$result=mysql_query("select * from products");
while($row=mysql_fetch_array($result)){
?>
<tr>
<!-- Displaying the shopping cart product -->
<td>
<img src="<?=$row['picture']?>" />
</td>
<td>
<b><?=$row['name']?>
</b><br/>
<?=$row['description']?>
<br/>
Price:<big style="color:#455E5B">
$<?=$row['price']?>
</big><br/><br/>
<a href="cart.php?id=<?=$row['serial']?>&action=add "><img src="images/add.png"/></a>
</td>
</tr>
<tr>
<td colspan="2">
<hr size="1"/>
</td>
<? }?>
</table>
</div>
</body>
</html>
It looks like you're using PHP short tags in your script (<? /* PHP statement */ ?>
). If any short_open_tag
setting in your php.ini file is set to Off
, then those PHP tags would cause issues.
The correct way to solve this in PHP 5.4 and later versions? Use <?php /* statement */ ?>
instead:
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Shopping Cart</title>
<!-- This page is for displaying the products -->
</head>
<body bgcolor="#000000">
<div align="center">
<h3 style="background-color:#FF0">Products</h3>
<a style="color:#FFFF00; text-decoration:none" href="cart.php?action=none"><span style="margin-left:500px;">
<img src="online/images/cart.png">Cart (<?= count($_SESSION['cart']) ?>)</span></a>
</br>
<table border="0" bgcolor="#f6f6f6" cellpadding="0px" width="600px">
<?php
//Fetching the product details from database
include("common/db.php");
$result = mysql_query("select * from products");
while ($row = mysql_fetch_array($result)){
?>
<tr>
<!-- Displaying the shopping cart product -->
<td>
<img src="<?= $row['picture'] ?>"/>
</td>
<td>
<b><?= $row['name'] ?>
</b><br/>
<?= $row['description'] ?>
<br/>
Price:<span style="font-size:larger;color:#455E5B">
$<?= $row['price'] ?>
</span><br/><br/>
<a href="cart.php?id=<?= $row['serial'] ?>&action=add "><img src="images/add.png"/></a>
</td>
</tr>
<tr>
<td colspan="2">
<hr size="1"/>
</td>
<?php } ?>
</table>
</div>
</body>
</html>
If, for some reason, you are unable to use PHP 5.4+ (which is bad; PHP 5.3 is no longer supported), then the easiest thing to do would be to also replace instances of <?= $value ?>
with <?php echo $value; ?>
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Shopping Cart</title>
<!-- This page is for displaying the products -->
</head>
<body bgcolor="#000000">
<div align="center">
<h3 style="background-color:#FF0">Products</h3>
<a style="color:#FFFF00; text-decoration:none" href="cart.php?action=none"><span style="margin-left:500px;">
<img src="online/images/cart.png">Cart (<?php echo count($_SESSION['cart']);?>)</span></a>
</br>
<table border="0" bgcolor="#f6f6f6" cellpadding="0px" width="600px">
<?php
//Fetching the product details from database
include("common/db.php");
$result = mysql_query("select * from products");
while ($row = mysql_fetch_array($result)){
?>
<tr>
<!-- Displaying the shopping cart product -->
<td>
<img src="<?php echo $row['picture'];?>"/>
</td>
<td>
<b><?php echo $row['name'];?>
</b><br/>
<?php echo $row['description'];?>
<br/>
Price:<span style="font-size:larger;color:#455E5B">
$<?php echo $row['price'];?>
</span><br/><br/>
<a href="cart.php?id=<?php echo $row['serial'];?>&action=add "><img src="images/add.png"/></a>
</td>
</tr>
<tr>
<td colspan="2">
<hr size="1"/>
</td>
<?php } ?>
</table>
</div>
</body>
</html>