i am getting this error- [26-Nov-2019 14:07:56 UTC] PHP Parse error: syntax error, unexpected '$rslastviewed' (T_VARIABLE), expecting ',' or ';' in /home/fbt5bixmgpkq/public_html/dailyShop/product.php on line 301
This is my code:
<?php
//Add the selected product id to an array when the product detail page is loaded
session_start();
if(!isset($_SESSION["lastviewed"])) {
$_SESSION["lastviewed"] = array();
}
//Store up to 5 product ids in my array
$maxelements = 5;
if (isset($_GET['id']) && $_GET['id'] <> "") {// if we have url parameter
//Prevent the same product being added to the array twice
if (in_array($_GET['id'], $_SESSION["lastviewed"])) { // if product id is already in the array
$_SESSION["lastviewed"] = array_diff($_SESSION["lastviewed"],array($_GET['id'])) ; // remove it
$_SESSION["lastviewed"] = array_values($_SESSION["lastviewed"]); //optionally, re-index the array
}
if (count($_SESSION["lastviewed"]) >= $maxelements) {//check the number of array elements
$_SESSION["lastviewed"] = array_slice($_SESSION["lastviewed"],1); // remove the first element if we have 5 already
array_push($_SESSION["lastviewed"],$_GET['id']);//add the current itemid to the array
} else {
array_push($_SESSION["lastviewed"],$_GET['id']);//add the current itemid to the array
}
}
?>
<?php
//Use the array contents to filter a recordset, so I can display images of the products with a hyperlink to the product details page.
@session_start();
$criteria = (isset($_SESSION["lastviewed"])?implode(", ",$_SESSION["lastviewed"]):"-1");
$rslastviewed = new WA_MySQLi_RS("rslastviewed",$PowerCMSConnection_i,0);
$rslastviewed->setQuery("SELECT products.id, products.productName, products.productImage1 FROM products WHERE products.id IN (?) ORDER BY FIELD (products.id, ?)");
$rslastviewed->bindParam("il", "".$criteria ."", "-1"); //criteria
$rslastviewed->bindParam("il", "".$criteria ."", "-1"); //listorder
$rslastviewed->execute();
?>
<!-- single sidebar -->
<div class="aa-sidebar-widget">
<h3>Recently Views</h3>
<div class="aa-recently-views">
<?php while(!$rslastviewed->atEnd())
{
?>
<ul>
<li>
line no-301 :- <a href="product-details.php?id=<?php echo htmlentities $rslastviewed->getColumnVal("id"); ?>" class="aa-cartbox-img">
<img alt="img" src="admin/productimages/<?php echo htmlentities $rslastviewed->getColumnVal("productImage1"); ?>" title="<?php echo htmlentities $rslastviewed->getColumnVal("id"); ?>"
width="150" /></a>
<div class="aa-cartbox-info">
<h4><a href="#"><?php echo htmlentities $rslastviewed->getColumnVal("productName"); ?></a></h4>
<p><?php echo htmlentities $rslastviewed->getColumnVal("productPrice"); ?></p>
</div>
</li>
</ul>
<?php
$rslastviewed->moveNext();
}
$rslastviewed->moveFirst();
?>
</div>
</div>