Recently I start with php and not because it gives me this error.
This code is onyl for show articles and total price of shopping cart when reload page, using PHPSESSID, if they have a better idea or an alternative for that function, they are appreciated!
INDEX.PHP
<?php require("php/DB_Functionss.php"); ?>
<!doctype html>
<html lang="es">
<head>
........
</head>
<body>
<div id="infoShopCart">
<a href="contShopping"><img src="img/shopping_cart.png" width="30px"/>
Artículos: <b id="cantArticles">0</b>
Total: $ <b id="totalPriceArticles">0.00</b></a>
<?php getCart(); ?>
</div>
.....
....
</body>
</html>
AND DB_Functions.php
session_start();
$sessionID = $_COOKIE['PHPSESSID'];
class DB_Functions {
private $db;
//put your code here
//constructor
function __construct() {
require_once 'DB_Connect.php';
//connecting to database
$this->db = new DB_Connect();
$this->db->connect();
}
//destructor
function __destruct() {
}
public function getCart(){
$query ="SELECT * FROM carrito ORDER BY id_pelicula";
$result = mysql_query($query) or die(mysql_error());
$no_of_rows = mysql_num_rows($result);
if($no_of_rows > 0) {
while ($row = mysql_fetch_assoc($result)) {
$totalItems = $totalItems + 1;
$movieTotalPrice = $movieTotalPrice + $row['precio_pelicula'];
}
echo ("Artículos: <b id='cantArticles'>"+$totalItems+"</b><otal: $ <b id='totalPriceArticles'>"+$totalPrice+"</b></a>");
} else {
return false;
}
}
You should initialize the object and then use its method. Like so: