PHP: In shopping cart, Fatal error: Call to undefined function getCart() -
recently start php , not because gives me error. code onyl show articles , total price of shopping cart when reload page, using phpsessid, if have better idea or alternative function, 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 code here //constructor function __construct() { require_once 'db_connect.php'; //connecting database $this->db = new db_connect(); $this->db->connect(); } //destructor function __destruct() { } public function getcart(){ $query ="select * carrito order 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 object , use method. so:
<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 $db_object = new db_functions(); $db_object->getcart(); ?> </div>
Comments
Post a Comment