Jump to content

hass1980

Members
  • Posts

    57
  • Joined

  • Last visited

    Never

Everything posted by hass1980

  1. I get the following statement string(20) "1,,,,1,1,1,1,1,1,1,1"
  2. Hi, I cant get any products to be displayed in the shopping cart as I keep getting the following errors. Notice: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,,,)' at line 1 SQL: SELECT * FROM product WHERE productid IN (1,,,,,,) in C:\wamp\www\myproject\inc\mysql.class.php on line 114 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\myproject\inc\mysql.class.php on line 156 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\myproject\inc\mysql.class.php on line 172 Here is the following table names and code from three files that might contain the error somewhere. admin Field Type Null Default Comments AdminID tinyint(4) No Username varchar(10) No Password varchar(10) No category Field Type Null Default Comments CatID tinyint(4) No CatName varchar(20) No CatDesc varchar(255) No CatImage char(5) No customer Field Type Null Default Comments CustomerID int(11) No Forename varchar(50) No Surname varchar(50) No Add1 varchar(50) No Add2 varchar(50) No Add3 varchar(50) No Postcode varchar(10) No Phone varchar(20) No Email varchar(100) No delivery_add Field Type Null Default Comments Delivery_Add_ID int(11) No CustomerID int(11) No CustForname varchar(50) No CustSurname varchar(50) No CustShipAdd1 varchar(50) No CustShipAdd2 varchar(50) No CustShipAdd3 varchar(50) No CustShipPostcode varchar(10) No login Field Type Null Default Comments LoginID int(11) No CustomerID int(11) No Username varchar(10) No Password varchar(10) No order Field Type Null Default Comments OrderID int(11) No CustomerID int(11) No Delivery_Add_ID int(11) Yes NULL OrderDate datetime Yes NULL OrderTotal double No OrderStatus char(1) No I order items Field Type Null Default Comments OrderItemsID int(11) No OrderID int(11) No ProductID int(11) No Quantity int(11) No product Field Type Null Default Comments ProductID int(11) No CatID tinyint(4) No ProductName varchar(100) No ProductDesc text No ProductImage varchar(30) No ProductPrice double No Code for the mysql.class.php <?php ob_start(); /** * Hide Notice errors. Mostly returned when it finds an undeclared variable. */ error_reporting(E_ALL & ~E_NOTICE); /** * MySQL Database Connection Class * @access public * @package SPLIB */ class MySQL { /** * MySQL server hostname * @access private * @var string */ var $host; /** * MySQL username * @access private * @var string */ var $dbUser; /** * MySQL user's password * @access private * @var string */ var $dbPass; /** * Name of database to use * @access private * @var string */ var $dbName; /** * MySQL Resource link identifier stored here * @access private * @var string */ var $dbConn; /** * Stores error messages for connection errors * @access private * @var string */ var $connectError; /** * MySQL constructor * @param string host (MySQL server hostname) * @param string dbUser (MySQL User Name) * @param string dbPass (MySQL User Password) * @param string dbName (Database to select) * @access public */ function MySQL ($host,$dbUser,$dbPass,$dbName) { $this->host=$host; $this->dbUser=$dbUser; $this->dbPass=$dbPass; $this->dbName=$dbName; $this->connectToDb(); } /** * Establishes connection to MySQL and selects a database * @return void * @access private */ function connectToDb () { // Make connection to MySQL server if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) { trigger_error('Could not connect to server'); $this->connectError=true; // Select database } else if ( !@mysql_select_db($this->dbName,$this->dbConn) ) { trigger_error('Could not select database'); $this->connectError=true; } } /** * Checks for MySQL errors * @return boolean * @access public */ function isError () { if ( $this->connectError ) return true; $error=mysql_error ($this->dbConn); if ( empty ($error) ) return false; else return true; } /** * Returns an instance of MySQLResult to fetch rows with * @param $sql string the database query to run * @return MySQLResult * @access public */ function query($sql) { if (!$queryResource=mysql_query($sql,$this->dbConn)) trigger_error ('Query failed: '.mysql_error($this->dbConn). ' SQL: '.$sql); return new MySQLResult($this,$queryResource); } } /** * MySQLResult Data Fetching Class * @access public * @package SPLIB */ class MySQLResult { /** * Instance of MySQL providing database connection * @access private * @var MySQL */ var $mysql; /** * Query resource * @access private * @var resource */ var $query; /** * MySQLResult constructor * @param object mysql (instance of MySQL class) * @param resource query (MySQL query resource) * @access public */ function MySQLResult(& $mysql,$query) { $this->mysql=& $mysql; $this->query=$query; } /** * Fetches a row from the result * @return array * @access public */ function fetch () { if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) ) { return $row; } else if ( $this->size() > 0 ) { mysql_data_seek($this->query,0); return false; } else { return false; } } /** * Returns the number of rows selected * @return int * @access public */ function size () { return mysql_num_rows($this->query); } /** * Returns the ID of the last row inserted * @return int * @access public */ function insertID () { return mysql_insert_id($this->mysql->dbConn); } /** * Checks for MySQL errors * @return boolean * @access public */ function isError () { return $this->mysql->isError(); } } ?> Code for functions.inc <?php /** * To Display the user shopping cart * @return string */ function showCart() { global $db; /** * Varibale declaration. */ $price = ''; $qty =''; $cart = $_SESSION['cart']; $total = 0; $output = ''; $output = '<form action="cart.php?action=update" method="post" id="contents">'; $output .= '<h4>Shopping Cart</h4><br>'; $output .= "<table cellpadding='0' cellspacing='0' width='98%' border='0' align='center' class='tableborder2'> <tr valign='middle' height='30'> <td align='left' class='listbg'> </td> <td align='left' class='listbg'>Product</td> <td align='left' class='listbg'>Product Price</td> <td align='left' class='listbg'>Quantity</td> <td align='left' class='listbg'>Total</td> </tr>"; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $sql = "SELECT * FROM product WHERE catid IN ($cart)"; $result = $db->query($sql); while ($row = $result->fetch()) { extract($row); $qty = $contents[$id]; $output .= "<tr valign='middle' height='30' class='list1bg' onmouseover='this.className=\"list2bg\"' onmouseout='this.className=\"list1bg\"'> <td align='left' class='normaltext'><a href='cart.php?action=delete&id=$id' class='r'>Remove</a></td> <td align='left' class='normaltext'>$name by $description</td> <td align='left' class='normaltext'>£ $price</td> <td align='left' class='normaltext'><input type='text' name='qty$id' value='$qty' size='3' maxlength='3' /></td> <td align='left' class='normaltext'>£".($price * $qty)."</td> </tr>"; $total += $price * $qty; } } else $output .= "<tr valign='middle' height='30'> <td colspan='10 class='message'> No Products In Shopping Cart</td> </tr>"; $output .= "<tr valign='middle' height='30' class='list1bg' onmouseover='this.className=\"list2bg\"' onmouseout='this.className=\"list1bg\"'> <td colspan='4' class='normalbold' align='right'>Grand Total : </td> <td align='left' class='normaltext'>£".($price * $qty)."</td> </tr>"; $button = ''; if ($cart) $button = '<button type="submit">Update cart</button>'; $output .= "<tr valign='middle' height='30' class='list1bg' onmouseover='this.className=\"list2bg\"' onmouseout='this.className=\"list1bg\"'> <td colspan='2' class='normalbold' align='right'>$button</td> <td colspan='2' class='normalbold' align='right'>Grand Total : </td> <td align='left' class='normaltext'>£".($price * $qty)."</td> </tr>"; $output .= '</table>'; $output .= '</form>'; return $output; } /** * To reformat the string to input to the database * @return string */ function GetSQLValueString($theValue, $theType='', $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : 0; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "''"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } /** * User login methods */ function loginUser() { global $db; $username = GetSQLValueString($_POST['username'],'text'); $password = GetSQLValueString($_POST['password'],'text'); $customers_sql = "SELECT * FROM ".CUSTOMER_TABLE." AS CU,".LOGIN_TABLE." AS LO WHERE CU.CustomerID=LO.CustomerID AND LO.Username=$username AND LO.Password=$password"; $customers_result = $db->query($customers_sql); if($customers_result->size()>0) { $customers_row = $customers_result->fetch(); $_SESSION['CustomerID'] = $customers_row['CustomerID']; } } /** * User registration methods */ function registerUser() { global $db; $forename = GetSQLValueString($_POST['forename'],'text'); $surname = GetSQLValueString($_POST['surname'],'text'); $add1 = GetSQLValueString($_POST['add1'],'text'); $add2 = GetSQLValueString($_POST['add2'],'text'); $add3 = GetSQLValueString($_POST['add3'],'text'); $postcode = GetSQLValueString($_POST['postcode'],'text'); $phone = GetSQLValueString($_POST['phone'],'text'); $email = GetSQLValueString($_POST['email'],'text'); $username = GetSQLValueString($_POST['username'],'text'); $password = GetSQLValueString($_POST['password'],'text'); $customer_sql = "INSERT INTO ".CUSTOMER_TABLE."(Forename,Surname,Add1,Add2,Add3,Postcode,Phone,Email) VALUES ($forename,$surname,$add1,$add2,$add3,$postcode,$phone,$email)"; echo $customer_sql; exit; $customer_result = $db->query($customer_sql); $customer_id = $customer_result->insertID(); $customer_sql = "INSERT INTO ".LOGIN_TABLE."(CustomerID,Username,Password) VALUES ($customer_id,$username,$password)"; $db->query($customer_sql); $_SESSION['CustomerID'] = $customer_id; return header("Location: index.php"); exit; } /** * Update user methods */ function updateUser() { global $db; $customer_id = $_SESSION['CustomerID']; $forename = GetSQLValueString($_POST['forename'],'text'); $surname = GetSQLValueString($_POST['surname'],'text'); $add1 = GetSQLValueString($_POST['add1'],'text'); $add2 = GetSQLValueString($_POST['add2'],'text'); $add3 = GetSQLValueString($_POST['add3'],'text'); $postcode = GetSQLValueString($_POST['postcode'],'text'); $phone = GetSQLValueString($_POST['phone'],'text'); $email = GetSQLValueString($_POST['email'],'text'); $username = GetSQLValueString($_POST['username'],'text'); $password = GetSQLValueString($_POST['password'],'text'); $customer_sql = "UPDATE ".CUSTOMER_TABLE." SET forename=$forename,surname=$surname,Add1=$add1,Add2=$add2,Add3=$add3,Postcode=$postcode,Phone=$phone,Email=$email WHERE CustomerID='$customer_id'"; $db->query($customer_sql); $customer_sql = "UPDATE ".LOGIN_TABLE." SET Username=$username,Password=$password WHERE CustomerID='$customer_id'"; $db->query($customer_sql); return header("Location: myaccount.php?action=myaccount"); exit; } /** * To display the user login, registration and myaccount page * @return string */ function myAccount() { global $db; $content = ''; switch ($_POST['action']) { case 'login': loginUser(); break; case 'register': registerUser(); break; case 'myaccount': updateUser(); break; } switch ($_GET['action']) { case 'login': $content = " <form method='POST' onsubmit='return loginCheck()' id='tableclass'> <input type='hidden' name='action' value='login'> <h4>Login</h4> <table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'> <tr valign='middle' height='30'> <td align='right' width='50%'>Username : </td> <td align='left' width='50%'><input type='text' name='username' id='username' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Password : </td> <td align='left'><input type='password' name='password' id='password' value=''></td> </tr> <tr valign='middle' height='30'> <td colspan='2' align='center'> <input type='submit' value=' Login ' name='btn_lgn'> <input type='reset' value=' Cancel ' name='btn_cel'> </td> </tr> </table> <br> </form>"; break; case 'register': $content = " <form method='POST' id='tableclass' name='registerform'> <input type='hidden' name='action' value='register'> <h4>Create an account</h4> <table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'> <tr valign='middle' height='30'> <td align='right' width='50%'>First Name : </td> <td align='left' width='50%'><input type='text' name='forename' id='forename' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Last Name : </td> <td align='left'><input type='text' name='surname' id='surname' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 1 : </td> <td align='left'><input type='text' name='add1' id='add1' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 2 : </td> <td align='left'><input type='text' name='add2' id='add2' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 3 : </td> <td align='left'><input type='text' name='add3' id='add3' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Postcode : </td> <td align='left'><input type='text' name='postcode' id='postcode' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Phone Number : </td> <td align='left'><input type='text' name='phone' id='phone' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Email Address : </td> <td align='left'><input type='text' name='email' id='email' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Username : </td> <td align='left'><input type='text' name='username' id='username' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Password : </td> <td align='left'><input type='password' name='password' id='password' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Re-enterPassword : </td> <td align='left'><input type='password' name='password1' id='password1' value=''></td> </tr> <tr valign='middle' height='30'> <td colspan='2' align='center'> <input type='button' value=' Register ' name='btn_reg' onclick='registerCheck()'> <input type='reset' value=' Cancel ' name='btn_cel'> </td> </tr> </table> <br> </form>"; break; case 'myaccount': $customers_sql = "SELECT * FROM customers AS CU,logins AS LO WHERE CU.id=LO.customer_id AND LO.customer_id=".$_SESSION['CustomerID']; $customers_result = $db->query($customers_sql); $customers_row = $customers_result->fetch(); $content = " <form method='POST' id='tableclass' name='registerform'> <input type='hidden' name='action' value='myaccount'> <h4>Myaccount</h4> <table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'> <tr valign='middle' height='30'> <td align='right' width='50%'>First Name : </td> <td align='left' width='50%'><input type='text' name='forename' id='forename' value='".$customers_row['forename']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Last Name : </td> <td align='left'><input type='text' name='surname' id='surname' value='".$customers_row['surname']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 1 : </td> <td align='left'><input type='text' name='add1' id='add1' value='".$customers_row['add1']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 2 : </td> <td align='left'><input type='text' name='add2' id='add2' value='".$customers_row['add2']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 3 : </td> <td align='left'><input type='text' name='add3' id='add3' value='".$customers_row['add3']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Postcode : </td> <td align='left'><input type='text' name='postcode' id='postcode' value='".$customers_row['postcode']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Phone Number : </td> <td align='left'><input type='text' name='phone' id='phone' value='".$customers_row['phone']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Email Address : </td> <td align='left'><input type='text' name='email' id='email' value='".$customers_row['email']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Username : </td> <td align='left'><input type='text' name='username' id='username' value='".$customers_row['username']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Password : </td> <td align='left'><input type='password' name='password' id='password' value='".$customers_row['password']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Re-enterPassword : </td> <td align='left'><input type='password' name='password1' id='password1' value='".$customers_row['password']."'></td> </tr> <tr valign='middle' height='30'> <td colspan='2' align='center'> <input type='button' value=' Update Details ' name='btn_reg' onclick='myaccountCheck()'> </td> </tr> </table> <br> </form>"; break; case 'logout': session_unregister('customer_id'); break; default: return header("Location: index.php"); break; } if((isset($_SESSION['CustomerID']) && $_SESSION['CustomerID']>0 && ($_REQUEST['action']=='login' || $_REQUEST['action']=='register')) || (!isset($_SESSION['CustomerID']) && ($_REQUEST['action']=='myaccount' || $_REQUEST['action']=='logout'))) { return header("Location: index.php"); exit; } return $content; } /** * To display user side header * @return string */ function siteHeader() { echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Millhouse</title> <LINK REL=StyleSheet HREF="css/style.css" TYPE="text/css" /> <script src="js/ajax.js"></script> <script src="js/common.js"></script> </head> <body> <div id="wrapper"> <div id="header"></div> <div id="navigation">'.writeShoppingCart().'</div> <div id="leftcolumn"> <p align="left"> </p> <h4> </h4> <h4>Browse by Category</h4> <ul id="nav"> <p> </p> <a href="index.php">Home</a> '.categoryListing().' <a href="">Contact Us</a> </ul> </div> <div id="rightcolumn">'; } /** * To display user side footer * @return string */ function siteFooter() { echo ' </div> <div id="footer"><p> </p><p> </p> </div> </body> </html>'; } /** * To display user top links * @return string */ function writeShoppingCart() { // $cart = $_SESSION['cart']; // if (!$cart) // { // $head = '<p>You have no items in your shopping cart</p>'; // } // else // { // // Parse the cart session variable // $items = explode(',',$cart); // $s = (count($items) > 1) ? 's':''; // $head = '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; // } $head = ''; $head .= '<a href="index.php">Home</a> | <a href="cart.php">Shopping Cart</a> | '; if(isset($_SESSION['CustomerID']) && $_SESSION['CustomerID']>0) $head .= '<a href="myaccount.php?action=myaccount">My account</a> | <a href="myaccount.php?action=logout">Logout</a></p>'; else $head .= '<a href="myaccount.php?action=login">Login</a> | <a href="myaccount.php?action=register">Create an account</a></p>'; return $head; } /** * To display the leftside/center categories * @return string */ function categoryListing($flag=0) { global $db; $categories_sql = "SELECT * FROM ".CATEGORY_TABLE." WHERE 1 ORDER BY CatName ASC"; $categories_result = $db->query($categories_sql); $categories = ''; if($flag==1) $categories = '<h4>Browse by Category</h4><p> </p><p> </p>'; if($categories_result->size()>0) { $i = 0; $row = 5; while ($categories_row = $categories_result->fetch()) { $CatID = $categories_row['CatID']; $CatName = $categories_row['CatName']; $CatImage = $categories_row['CatImage']; (isset($_GET['cat_id']) && $_GET['cat_id']==$CatID) ? $class='selected' : $class=''; if($flag==0) $categories .= "<a href='index.php?cat_id=$CatID' class='$class'>$CatName</a>"; else { $categories .= " <div class='img'> <a href='index.php?cat_id=$CatID'><img src='images/category/$CatID.$CatImage' alt='storage' width='110' height='90' /></a> <div class='desc'>$CatName</div> </div>"; } } } return $categories; } /** * To display products in the specified category * @return string */ function productListing() { global $db; $cat_id = $_GET['cat_id']; $categories_sql = "SELECT * FROM ".CATEGORY_TABLE." WHERE CatID='$cat_id'"; $categories_result = $db->query($categories_sql); if($categories_result->size()==0) { return header("Location: index.php");; exit; } $categories_row = $categories_result->fetch(); $caregory_name = $categories_row['CatName']; $products_sql = "SELECT * FROM ".PRODUCT_TABLE." WHERE CatID='$cat_id' ORDER BY ProductName ASC"; $products_result = $db->query($products_sql); $products = "<h4>Products in \"$caregory_name\"</h4><br>"; if($products_result->size()>0) { while ($products_row = $products_result->fetch()) { $product_id = $products_row['ProductID']; $product_name = $products_row['ProductName']; $product_desc = $products_row['ProductDesc']; $product_price = $products_row['ProductPrice']; $product_image = $products_row['ProductImage']; $products .= " <div class='img'> <a href=''><img src='images/product/$product_id.$product_image' alt='storage' width='110' height='90' /></a> <div class='desc'>\"$product_name\" by $product_desc</div> <div class='desc'>£ $product_price</div> <div class='desc'><a href='cart.php?action=add&id=$product_id'>Add to cart</a></div> </div>"; } } else { $products .= "<div class='message'><br><br>No Products Found</div>"; } // $products .= "<div style='clear:both'></div>"; // $products .= categoryListing(2); return $products; } ?> Cart.php <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart=$action=''; $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; if($_SERVER['QUERY_STRING']!='') { return header("Location: cart.php"); exit; } siteHeader(); echo showCart(); siteFooter(); ?>
  3. Hi, I cant get any products to be displayed in the shopping cart as I keep getting ht e following errors. Notice: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,,,)' at line 1 SQL: SELECT * FROM product WHERE productid IN (1,,,,,,) in C:\wamp\www\myproject\inc\mysql.class.php on line 114 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\myproject\inc\mysql.class.php on line 156 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\myproject\inc\mysql.class.php on line 172 Code for the mysql.class.php <?php ob_start(); /** * Hide Notice errors. Mostly returned when it finds an undeclared variable. */ error_reporting(E_ALL & ~E_NOTICE); /** * MySQL Database Connection Class * @access public * @package SPLIB */ class MySQL { /** * MySQL server hostname * @access private * @var string */ var $host; /** * MySQL username * @access private * @var string */ var $dbUser; /** * MySQL user's password * @access private * @var string */ var $dbPass; /** * Name of database to use * @access private * @var string */ var $dbName; /** * MySQL Resource link identifier stored here * @access private * @var string */ var $dbConn; /** * Stores error messages for connection errors * @access private * @var string */ var $connectError; /** * MySQL constructor * @param string host (MySQL server hostname) * @param string dbUser (MySQL User Name) * @param string dbPass (MySQL User Password) * @param string dbName (Database to select) * @access public */ function MySQL ($host,$dbUser,$dbPass,$dbName) { $this->host=$host; $this->dbUser=$dbUser; $this->dbPass=$dbPass; $this->dbName=$dbName; $this->connectToDb(); } /** * Establishes connection to MySQL and selects a database * @return void * @access private */ function connectToDb () { // Make connection to MySQL server if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) { trigger_error('Could not connect to server'); $this->connectError=true; // Select database } else if ( !@mysql_select_db($this->dbName,$this->dbConn) ) { trigger_error('Could not select database'); $this->connectError=true; } } /** * Checks for MySQL errors * @return boolean * @access public */ function isError () { if ( $this->connectError ) return true; $error=mysql_error ($this->dbConn); if ( empty ($error) ) return false; else return true; } /** * Returns an instance of MySQLResult to fetch rows with * @param $sql string the database query to run * @return MySQLResult * @access public */ function query($sql) { if (!$queryResource=mysql_query($sql,$this->dbConn)) trigger_error ('Query failed: '.mysql_error($this->dbConn). ' SQL: '.$sql); return new MySQLResult($this,$queryResource); } } /** * MySQLResult Data Fetching Class * @access public * @package SPLIB */ class MySQLResult { /** * Instance of MySQL providing database connection * @access private * @var MySQL */ var $mysql; /** * Query resource * @access private * @var resource */ var $query; /** * MySQLResult constructor * @param object mysql (instance of MySQL class) * @param resource query (MySQL query resource) * @access public */ function MySQLResult(& $mysql,$query) { $this->mysql=& $mysql; $this->query=$query; } /** * Fetches a row from the result * @return array * @access public */ function fetch () { if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) ) { return $row; } else if ( $this->size() > 0 ) { mysql_data_seek($this->query,0); return false; } else { return false; } } /** * Returns the number of rows selected * @return int * @access public */ function size () { return mysql_num_rows($this->query); } /** * Returns the ID of the last row inserted * @return int * @access public */ function insertID () { return mysql_insert_id($this->mysql->dbConn); } /** * Checks for MySQL errors * @return boolean * @access public */ function isError () { return $this->mysql->isError(); } } ?> Code for the functions.inc.php <?php /** * To Display the user shopping cart * @return string */ function showCart() { global $db; /** * Varibale declaration. */ $price = ''; $qty =''; $cart = $_SESSION['cart']; $total = 0; $output = ''; $output = '<form action="cart.php?action=update" method="post" id="contents">'; $output .= '<h4>Shopping Cart</h4><br>'; $output .= "<table cellpadding='0' cellspacing='0' width='98%' border='0' align='center' class='tableborder2'> <tr valign='middle' height='30'> <td align='left' class='listbg'> </td> <td align='left' class='listbg'>Product</td> <td align='left' class='listbg'>Product Price</td> <td align='left' class='listbg'>Quantity</td> <td align='left' class='listbg'>Total</td> </tr>"; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $sql = "SELECT * FROM product WHERE productid IN ($cart)"; $result = $db->query($sql); while ($row = $result->fetch()) { extract($row); $qty = $contents[$id]; $output .= "<tr valign='middle' height='30' class='list1bg' onmouseover='this.className=\"list2bg\"' onmouseout='this.className=\"list1bg\"'> <td align='left' class='normaltext'><a href='cart.php?action=delete&id=$id' class='r'>Remove</a></td> <td align='left' class='normaltext'>$name by $description</td> <td align='left' class='normaltext'>£ $price</td> <td align='left' class='normaltext'><input type='text' name='qty$id' value='$qty' size='3' maxlength='3' /></td> <td align='left' class='normaltext'>£".($price * $qty)."</td> </tr>"; $total += $price * $qty; } } else $output .= "<tr valign='middle' height='30'> <td colspan='10 class='message'> No Products In Shopping Cart</td> </tr>"; $output .= "<tr valign='middle' height='30' class='list1bg' onmouseover='this.className=\"list2bg\"' onmouseout='this.className=\"list1bg\"'> <td colspan='4' class='normalbold' align='right'>Grand Total : </td> <td align='left' class='normaltext'>£".($price * $qty)."</td> </tr>"; $button = ''; if ($cart) $button = '<button type="submit">Update cart</button>'; $output .= "<tr valign='middle' height='30' class='list1bg' onmouseover='this.className=\"list2bg\"' onmouseout='this.className=\"list1bg\"'> <td colspan='2' class='normalbold' align='right'>$button</td> <td colspan='2' class='normalbold' align='right'>Grand Total : </td> <td align='left' class='normaltext'>£".($price * $qty)."</td> </tr>"; $output .= '</table>'; $output .= '</form>'; return $output; } /** * To reformat the string to input to the database * @return string */ function GetSQLValueString($theValue, $theType='', $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : 0; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "''"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } /** * User login methods */ function loginUser() { global $db; $username = GetSQLValueString($_POST['username'],'text'); $password = GetSQLValueString($_POST['password'],'text'); $customers_sql = "SELECT * FROM ".CUSTOMER_TABLE." AS CU,".LOGIN_TABLE." AS LO WHERE CU.CustomerID=LO.CustomerID AND LO.Username=$username AND LO.Password=$password"; $customers_result = $db->query($customers_sql); if($customers_result->size()>0) { $customers_row = $customers_result->fetch(); $_SESSION['CustomerID'] = $customers_row['CustomerID']; } } /** * User registration methods */ function registerUser() { global $db; $forename = GetSQLValueString($_POST['forename'],'text'); $surname = GetSQLValueString($_POST['surname'],'text'); $add1 = GetSQLValueString($_POST['add1'],'text'); $add2 = GetSQLValueString($_POST['add2'],'text'); $add3 = GetSQLValueString($_POST['add3'],'text'); $postcode = GetSQLValueString($_POST['postcode'],'text'); $phone = GetSQLValueString($_POST['phone'],'text'); $email = GetSQLValueString($_POST['email'],'text'); $username = GetSQLValueString($_POST['username'],'text'); $password = GetSQLValueString($_POST['password'],'text'); $customer_sql = "INSERT INTO ".CUSTOMER_TABLE."(Forename,Surname,Add1,Add2,Add3,Postcode,Phone,Email) VALUES ($forename,$surname,$add1,$add2,$add3,$postcode,$phone,$email)"; echo $customer_sql; exit; $customer_result = $db->query($customer_sql); $customer_id = $customer_result->insertID(); $customer_sql = "INSERT INTO ".LOGIN_TABLE."(CustomerID,Username,Password) VALUES ($customer_id,$username,$password)"; $db->query($customer_sql); $_SESSION['CustomerID'] = $customer_id; return header("Location: index.php"); exit; } /** * Update user methods */ function updateUser() { global $db; $customer_id = $_SESSION['CustomerID']; $forename = GetSQLValueString($_POST['forename'],'text'); $surname = GetSQLValueString($_POST['surname'],'text'); $add1 = GetSQLValueString($_POST['add1'],'text'); $add2 = GetSQLValueString($_POST['add2'],'text'); $add3 = GetSQLValueString($_POST['add3'],'text'); $postcode = GetSQLValueString($_POST['postcode'],'text'); $phone = GetSQLValueString($_POST['phone'],'text'); $email = GetSQLValueString($_POST['email'],'text'); $username = GetSQLValueString($_POST['username'],'text'); $password = GetSQLValueString($_POST['password'],'text'); $customer_sql = "UPDATE ".CUSTOMER_TABLE." SET forename=$forename,surname=$surname,Add1=$add1,Add2=$add2,Add3=$add3,Postcode=$postcode,Phone=$phone,Email=$email WHERE CustomerID='$customer_id'"; $db->query($customer_sql); $customer_sql = "UPDATE ".LOGIN_TABLE." SET Username=$username,Password=$password WHERE CustomerID='$customer_id'"; $db->query($customer_sql); return header("Location: myaccount.php?action=myaccount"); exit; } /** * To display the user login, registration and myaccount page * @return string */ function myAccount() { global $db; $content = ''; switch ($_POST['action']) { case 'login': loginUser(); break; case 'register': registerUser(); break; case 'myaccount': updateUser(); break; } switch ($_GET['action']) { case 'login': $content = " <form method='POST' onsubmit='return loginCheck()' id='tableclass'> <input type='hidden' name='action' value='login'> <h4>Login</h4> <table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'> <tr valign='middle' height='30'> <td align='right' width='50%'>Username : </td> <td align='left' width='50%'><input type='text' name='username' id='username' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Password : </td> <td align='left'><input type='password' name='password' id='password' value=''></td> </tr> <tr valign='middle' height='30'> <td colspan='2' align='center'> <input type='submit' value=' Login ' name='btn_lgn'> <input type='reset' value=' Cancel ' name='btn_cel'> </td> </tr> </table> <br> </form>"; break; case 'register': $content = " <form method='POST' id='tableclass' name='registerform'> <input type='hidden' name='action' value='register'> <h4>Create an account</h4> <table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'> <tr valign='middle' height='30'> <td align='right' width='50%'>First Name : </td> <td align='left' width='50%'><input type='text' name='forename' id='forename' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Last Name : </td> <td align='left'><input type='text' name='surname' id='surname' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 1 : </td> <td align='left'><input type='text' name='add1' id='add1' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 2 : </td> <td align='left'><input type='text' name='add2' id='add2' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 3 : </td> <td align='left'><input type='text' name='add3' id='add3' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Postcode : </td> <td align='left'><input type='text' name='postcode' id='postcode' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Phone Number : </td> <td align='left'><input type='text' name='phone' id='phone' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Email Address : </td> <td align='left'><input type='text' name='email' id='email' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Username : </td> <td align='left'><input type='text' name='username' id='username' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Password : </td> <td align='left'><input type='password' name='password' id='password' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Re-enterPassword : </td> <td align='left'><input type='password' name='password1' id='password1' value=''></td> </tr> <tr valign='middle' height='30'> <td colspan='2' align='center'> <input type='button' value=' Register ' name='btn_reg' onclick='registerCheck()'> <input type='reset' value=' Cancel ' name='btn_cel'> </td> </tr> </table> <br> </form>"; break; case 'myaccount': $customers_sql = "SELECT * FROM customers AS CU,logins AS LO WHERE CU.id=LO.customer_id AND LO.customer_id=".$_SESSION['CustomerID']; $customers_result = $db->query($customers_sql); $customers_row = $customers_result->fetch(); $content = " <form method='POST' id='tableclass' name='registerform'> <input type='hidden' name='action' value='myaccount'> <h4>Myaccount</h4> <table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'> <tr valign='middle' height='30'> <td align='right' width='50%'>First Name : </td> <td align='left' width='50%'><input type='text' name='forename' id='forename' value='".$customers_row['forename']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Last Name : </td> <td align='left'><input type='text' name='surname' id='surname' value='".$customers_row['surname']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 1 : </td> <td align='left'><input type='text' name='add1' id='add1' value='".$customers_row['add1']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 2 : </td> <td align='left'><input type='text' name='add2' id='add2' value='".$customers_row['add2']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Address 3 : </td> <td align='left'><input type='text' name='add3' id='add3' value='".$customers_row['add3']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Postcode : </td> <td align='left'><input type='text' name='postcode' id='postcode' value='".$customers_row['postcode']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Phone Number : </td> <td align='left'><input type='text' name='phone' id='phone' value='".$customers_row['phone']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Email Address : </td> <td align='left'><input type='text' name='email' id='email' value='".$customers_row['email']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Username : </td> <td align='left'><input type='text' name='username' id='username' value='".$customers_row['username']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Password : </td> <td align='left'><input type='password' name='password' id='password' value='".$customers_row['password']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Re-enterPassword : </td> <td align='left'><input type='password' name='password1' id='password1' value='".$customers_row['password']."'></td> </tr> <tr valign='middle' height='30'> <td colspan='2' align='center'> <input type='button' value=' Update Details ' name='btn_reg' onclick='myaccountCheck()'> </td> </tr> </table> <br> </form>"; break; case 'logout': session_unregister('customer_id'); break; default: return header("Location: index.php"); break; } if((isset($_SESSION['CustomerID']) && $_SESSION['CustomerID']>0 && ($_REQUEST['action']=='login' || $_REQUEST['action']=='register')) || (!isset($_SESSION['CustomerID']) && ($_REQUEST['action']=='myaccount' || $_REQUEST['action']=='logout'))) { return header("Location: index.php"); exit; } return $content; } /** * To display user side header * @return string */ function siteHeader() { echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <LINK REL=StyleSheet HREF="css/style.css" TYPE="text/css" /> <script src="js/ajax.js"></script> <script src="js/common.js"></script> </head> <body> <div id="wrapper"> <div id="header"></div> <div id="navigation">'.writeShoppingCart().'</div> <div id="leftcolumn"> <p align="left"> </p> <h4> </h4> <h4>Browse by Category</h4> <ul id="nav"> <p> </p> <a href="index.php">Home</a> '.categoryListing().' <a href="">Contact Us</a> </ul> </div> <div id="rightcolumn">'; } /** * To display user side footer * @return string */ function siteFooter() { echo ' </div> <div id="footer"><p> </p><p> </p> </div> </body> </html>'; } /** * To display user top links * @return string */ function writeShoppingCart() { // $cart = $_SESSION['cart']; // if (!$cart) // { // $head = '<p>You have no items in your shopping cart</p>'; // } // else // { // // Parse the cart session variable // $items = explode(',',$cart); // $s = (count($items) > 1) ? 's':''; // $head = '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; // } $head = ''; $head .= '<a href="index.php">Home</a> | <a href="cart.php">Shopping Cart</a> | '; if(isset($_SESSION['CustomerID']) && $_SESSION['CustomerID']>0) $head .= '<a href="myaccount.php?action=myaccount">My account</a> | <a href="myaccount.php?action=logout">Logout</a></p>'; else $head .= '<a href="myaccount.php?action=login">Login</a> | <a href="myaccount.php?action=register">Create an account</a></p>'; return $head; } /** * To display the leftside/center categories * @return string */ function categoryListing($flag=0) { global $db; $categories_sql = "SELECT * FROM ".CATEGORY_TABLE." WHERE 1 ORDER BY CatName ASC"; $categories_result = $db->query($categories_sql); $categories = ''; if($flag==1) $categories = '<h4>Browse by Category</h4><p> </p><p> </p>'; if($categories_result->size()>0) { $i = 0; $row = 5; while ($categories_row = $categories_result->fetch()) { $CatID = $categories_row['CatID']; $CatName = $categories_row['CatName']; $CatImage = $categories_row['CatImage']; (isset($_GET['cat_id']) && $_GET['cat_id']==$CatID) ? $class='selected' : $class=''; if($flag==0) $categories .= "<a href='index.php?cat_id=$CatID' class='$class'>$CatName</a>"; else { $categories .= " <div class='img'> <a href='index.php?cat_id=$CatID'><img src='images/category/$CatID.$CatImage' alt='storage' width='110' height='90' /></a> <div class='desc'>$CatName</div> </div>"; } } } return $categories; } /** * To display products in the specified category * @return string */ function productListing() { global $db; $cat_id = $_GET['cat_id']; $categories_sql = "SELECT * FROM ".CATEGORY_TABLE." WHERE CatID='$cat_id'"; $categories_result = $db->query($categories_sql); if($categories_result->size()==0) { return header("Location: index.php");; exit; } $categories_row = $categories_result->fetch(); $caregory_name = $categories_row['CatName']; $products_sql = "SELECT * FROM ".PRODUCT_TABLE." WHERE CatID='$cat_id' ORDER BY ProductName ASC"; $products_result = $db->query($products_sql); $products = "<h4>Products in \"$caregory_name\"</h4><br>"; if($products_result->size()>0) { while ($products_row = $products_result->fetch()) { $product_id = $products_row['ProductID']; $product_name = $products_row['ProductName']; $product_desc = $products_row['ProductDesc']; $product_price = $products_row['ProductPrice']; $product_image = $products_row['ProductImage']; $products .= " <div class='img'> <a href=''><img src='images/product/$product_id.$product_image' alt='storage' width='110' height='90' /></a> <div class='desc'>\"$product_name\" by $product_desc</div> <div class='desc'>£ $product_price</div> <div class='desc'><a href='cart.php?action=add&id=$product_id'>Add to cart</a></div> </div>"; } } else { $products .= "<div class='message'><br><br>No Products Found</div>"; } // $products .= "<div style='clear:both'></div>"; // $products .= categoryListing(2); return $products; } ?>
  4. Hi Im having trouble with my registering script, I'm getting this error. An error occurred in script 'C:\wamp\www\ch16\register.php' on line 10: require_once(/path/to/mysqli_connect.php) [function.require-once]: failed to open stream: No such file or directory <?php require_once ('includes/config.inc.php'); $page_title = 'Register'; include ('includes/header.html'); if (isset($_POST['submitted'])) { // Handle the form. require_once (MYSQL); // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p = FALSE; // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) { $fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']); } else { echo '<p class="error">Please enter your first name!</p>'; } // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Please enter your last name!</p>'; } // Check for an email address: if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email'])) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); } else { echo '<p class="error">Please enter a valid email address!</p>'; } // Check for a password and match against the confirmed password: if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { echo '<p class="error">Please enter a valid password!</p>'; } if ($fn && $ln && $e && $p) { // If everything's OK... // Make sure the email address is available: $q = "SELECT user_id FROM users WHERE email='$e'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 0) { // Available. // Create the activation code: $a = md5(uniqid(rand(), true)); // Add the user to the database: $q = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', '$a', NOW() )"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Send the email: $body = "Thank you for registering at <whatever site>. To activate your account, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'], 'Registration Confirmation', $body, 'From: admin@sitename.com'); // Finish the page: echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>'; include ('includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { // If it did not run OK. echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; } } else { // The email address is not available. echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>'; } } else { // If one of the data tests failed. echo '<p class="error">Please re-enter your passwords and try again.</p>'; } mysqli_close($dbc); } // End of the main Submit conditional. ?> <h1>Register</h1> <form action="register.php" method="post"> <fieldset> <p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength="20" value="<?php if (isset($trimmed['first_name'])) echo $trimmed['first_name']; ?>" /></p> <p><b>Last Name:</b> <input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed['last_name'])) echo $trimmed['last_name']; ?>" /></p> <p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /> </p> <p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" /> <small>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small></p> <p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Register" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php // Include the HTML footer. include ('includes/footer.html'); ?>
  5. Hi Im getting the following errors Notice: Query failed: Table 'cart-demo.products' doesn't exist SQL: SELECT * FROM products WHERE id IN (1,1) in C:\wamp\www\myproject\inc\mysql.class.php on line 113 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\myproject\inc\mysql.class.php on line 155 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\myproject\inc\mysql.class.php on line 171 <?php ob_start(); /** * Hide Notice errors. Mostly returned when it finds an undeclared variable. */ error_reporting(E_ALL & ~E_NOTICE); /** * MySQL Database Connection Class * @access public * @package SPLIB */ class MySQL { /** * MySQL server hostname * @access private * @var string */ var $host; /** * MySQL username * @access private * @var string */ var $dbUser; /** * MySQL user's password * @access private * @var string */ var $dbPass; /** * Name of database to use * @access private * @var string */ var $dbName; /** * MySQL Resource link identifier stored here * @access private * @var string */ var $dbConn; /** * Stores error messages for connection errors * @access private * @var string */ var $connectError; /** * MySQL constructor * @param string host (MySQL server hostname) * @param string dbUser (MySQL User Name) * @param string dbPass (MySQL User Password) * @param string dbName (Database to select) * @access public */ function MySQL ($host,$dbUser,$dbPass,$dbName) { $this->host=$host; $this->dbUser=$dbUser; $this->dbPass=$dbPass; $this->dbName=$dbName; $this->connectToDb(); } /** * Establishes connection to MySQL and selects a database * @return void * @access private */ function connectToDb () { // Make connection to MySQL server if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) { trigger_error('Could not connect to server'); $this->connectError=true; // Select database } else if ( !@mysql_select_db($this->dbName,$this->dbConn) ) { trigger_error('Could not select database'); $this->connectError=true; } } /** * Checks for MySQL errors * @return boolean * @access public */ function isError () { if ( $this->connectError ) return true; $error=mysql_error ($this->dbConn); if ( empty ($error) ) return false; else return true; } /** * Returns an instance of MySQLResult to fetch rows with * @param $sql string the database query to run * @return MySQLResult * @access public */ function query($sql) { if (!$queryResource=mysql_query($sql,$this->dbConn)) trigger_error ('Query failed: '.mysql_error($this->dbConn).' SQL: '.$sql); return new MySQLResult($this,$queryResource); } } /** * MySQLResult Data Fetching Class * @access public * @package SPLIB */ class MySQLResult { /** * Instance of MySQL providing database connection * @access private * @var MySQL */ var $mysql; /** * Query resource * @access private * @var resource */ var $query; /** * MySQLResult constructor * @param object mysql (instance of MySQL class) * @param resource query (MySQL query resource) * @access public */ function MySQLResult(& $mysql,$query) { $this->mysql=& $mysql; $this->query=$query; } /** * Fetches a row from the result * @return array * @access public */ function fetch () { if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) ) { return $row; } else if ( $this->size() > 0 ) { mysql_data_seek($this->query,0); return false; } else { return false; } } /** * Returns the number of rows selected * @return int * @access public */ function size () { return mysql_num_rows($this->query); } /** * Returns the ID of the last row inserted * @return int * @access public */ function insertID () { return mysql_insert_id($this->mysql->dbConn); } /** * Checks for MySQL errors * @return boolean * @access public */ function isError () { return $this->mysql->isError(); } } ?>
  6. heres the functions.inc.php <?php function GetSQLValueString($theValue, $theType='', $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : 0; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "''"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } function siteHeader($array='') { if(!is_array($array)) $array = array(); echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <LINK REL=StyleSheet HREF="../css/style.css" TYPE="text/css" /> <script src="../js/ajax.js"></script> <script src="../js/common.js"></script> </head> <body> <div id="wrapper"> <div id="header"></div> <div id="leftcolumn"> <ul id="nav">'; if(isset($_SESSION['AdminID'])) { echo ' <a href="index.php" class="'.$array['index'].'">Home</a> <a href="categories.php" class="'.$array['categories'].'">Category</a> <a href="products.php" class="'.$array['products'].'">Products</a> <a href="myaccount.php?action=myaccount" class="'.$array['myaccount'].'">My Account</a> <a href="myaccount.php?action=logout">Logout</a>'; } else { echo ' <a href="myaccount.php?action=login">Login</a>'; } echo '</ul> </div> <div id="rightcolumn">'; } function siteFooter() { echo ' </div> <div id="footer"><p> </p><p> </p> </div> </body> </html>'; } function adminHeads() { $head = '<h1>Adminstration Panel</h1><p>Your Shopping Cart</p>'; if(isset($_SESSION['AdminID']) && $_SESSION['AdminID']>0) $head .= '<p align="right"><a href="categories.php?action=view">Categories</a> / <a href="products.php?action=view">Products</a> / <a href="myaccount.php?action=myaccount">My account</a> / <a href="myaccount.php?action=logout">Logout</a></p>'; return $head; } function myAccount() { global $db; $content = ''; switch ($_POST['action']) { case 'login': loginUser(); break; case 'myaccount': updateUser(); break; } If(isset($_GET['msg'])) $content = "<div class='message' align='center'><br>".$_GET['msg']."</div>"; switch ($_GET['action']) { case 'login': $content .= " <form method='POST' onsubmit='return loginCheck()' id='tableclass'> <input type='hidden' name='action' value='login'> <h1>Login</h1> <table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'> <tr valign='middle' height='30'> <td align='right' width='50%'>Username : </td> <td align='left' width='50%'><input type='text' name='username' id='username' value=''></td> </tr> <tr valign='middle' height='30'> <td align='right'>Password : </td> <td align='left'><input type='password' name='password' id='password' value=''></td> </tr> <tr valign='middle' height='30'> <td colspan='2' align='center'> <input type='submit' value=' Login ' name='btn_lgn'> <input type='reset' value=' Cancel ' name='btn_cel'> </td> </tr> </table> <br> </form>"; break; case 'myaccount': $customers_sql = "SELECT * FROM ".ADMIN_TABLE." WHERE AdminID=".$_SESSION['AdminID']; $customers_result = $db->query($customers_sql); $customers_row = $customers_result->fetch(); $content .= " <form method='POST' id='tableclass' name='registerform'> <input type='hidden' name='action' value='myaccount'> <h1>Myaccount</h1> <table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'> <tr valign='middle' height='30'> <td align='right'>Username : </td> <td align='left'><input type='text' name='username' id='username' value='".$customers_row['Username']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Password : </td> <td align='left'><input type='password' name='password' id='password' value='".$customers_row['Password']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Re-enterPassword : </td> <td align='left'><input type='password' name='password1' id='password1' value='".$customers_row['Password']."'></td> </tr> <tr valign='middle' height='30'> <td colspan='2' align='center'> <input type='button' value=' Update Details ' name='btn_reg' onclick='myaccountAdminCheck()'> </td> </tr> </table> <br> </form>"; break; case 'logout': session_unregister('admin_id'); break; default: return header("Location: index.php"); break; } if((isset($_SESSION['AdminID']) && $_SESSION['AdminID']>0 && ($_REQUEST['action']=='login')) || (!isset($_SESSION['AdminID']) && ($_REQUEST['action']=='myaccount' || $_REQUEST['action']=='logout'))) { return header("Location: index.php"); exit; } return $content; } function loginUser() { global $db; $username = GetSQLValueString($_POST['username'],'text'); $password = GetSQLValueString($_POST['password'],'text'); $customers_sql = "SELECT * FROM ".ADMIN_TABLE." WHERE Username=$username AND Password=$password"; $customers_result = $db->query($customers_sql); if($customers_result->size()>0) { $customers_row = $customers_result->fetch(); $_SESSION['AdminID'] = $customers_row['AdminID']; return header("Location: products.php?action=view&msg=Successfully LoggedIn"); } else { return header("Location: myaccount.php?action=myaccount&msg=Invalid Login Details"); } exit; } function updateUser() { global $db; $customer_id = $_SESSION['AdminID']; $username = GetSQLValueString($_POST['username'],'text'); $password = GetSQLValueString($_POST['password'],'text'); $customer_sql = "UPDATE ".ADMIN_TABLE." SET Username=$username,Password=$password WHERE AdminID='$customer_id'"; $db->query($customer_sql); return header("Location: myaccount.php?action=myaccount&msg=Details Updated"); exit; } ?> products.inc.php <?php function products() { global $db; $content = ''; switch ($_POST['action']) { case 'add': addProduct(); break; case 'edit': updateProduct(); break; } $content = ''; If(isset($_GET['msg'])) $content = "<div class='message' align='center'><br>".$_GET['msg']."</div>"; switch ($_GET['action']) { case 'edit': case 'add': (!isset($_GET['id'])) ? $head='Add Product' : $head='Edit Product'; (!isset($_GET['id'])) ? $button='Add Product' : $button='Update Product'; $product_row = array(); if(isset($_GET['id'])) { $product_sql = "SELECT * FROM ".PRODUCT_TABLE." WHERE ProductID=".$_GET['id']; $product_result = $db->query($product_sql); $product_row = $product_result->fetch(); $image = " <tr valign='top' height='30'> <td align='right'>Current Image : </td> <td align='left'><img type='file' src='../images/product/".$_GET['id'].'.'.$product_row['ProductImage']."' width='110' height='90'></td> </tr>"; } $content .= " <form method='POST' id='tableclass' name='registerform' onsubmit='return checkProduct()' enctype='multipart/form-data'> <input type='hidden' name='action' id='action' value='".$_GET['action']."'> <h4>Product Management - $head</h4> <table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'> <tr valign='middle' height='30'> <td align='right'>Product Name : </td> <td align='left'><input type='text' name='name' id='name' value='".$product_row['ProductName']."'></td> </tr> <tr valign='top' height='30'> <td align='right'>Description : </td> <td align='left'><textarea name='description' id='description' cols='50' rows='5'>".$product_row['ProductDesc']."</textarea></td> </tr> <tr valign='middle' height='30'> <td align='right'>Category : </td> <td align='left'>".category($product_row['CatID'])."</td> </tr> $image <tr valign='middle' height='30'> <td align='right'>Image : </td> <td align='left'><input type='file' name='image' id='image' value='".$product_row['ProductImage']."'></td> </tr> <tr valign='middle' height='30'> <td align='right'>Price : </td> <td align='left'><input type='text' name='price' id='price' value='".$product_row['ProductPrice']."'></td> </tr> <tr valign='middle' height='30'> <td colspan='2' align='center'> <input type='submit' value=' $button ' name='btn_reg' onclick=''> </td> </tr> </table> <br> </form>"; break; case 'delete': deleteProduct($_GET['id']); break; case 'view': default: $categories_sql = "SELECT * FROM ".PRODUCT_TABLE." AS PR,".CATEGORY_TABLE." AS CA WHERE PR.CatID=CA.CatID ORDER BY PR.ProductName ASC"; $categories_result = $db->query($categories_sql); $content .= " <h4>Product Management</h4> <div align='center'> <div align='right'><a href='products.php?action=add' class='links'>Add New Product</a> </div> <table cellpadding='0' cellspacing='0' width='98%' border='0' align='center' class='tableborder2'> <tr valign='middle' height='30'> <td align='left' class='listbg'>Product Name</td> <td align='left' class='listbg'>Category</td> <td align='center' width='50%' class='listbg'>Action</td> </tr>"; if($categories_result->size()>0) { $i = 1; while ($categories_row = $categories_result->fetch()) { $content .= " <tr valign='middle' height='30' class='list1bg' onmouseover='this.className=\"list2bg\"' onmouseout='this.className=\"list1bg\"'> <td align='left' class='normaltext'>".$categories_row['ProductName']."</td> <td align='left' class='normaltext'>".$categories_row['CatName']."</td> <td align='center' class='normaltext'><a href='products.php?action=edit&id=".$categories_row['ProductID']."' class='links'>Edit</a> / <a href='products.php?action=delete&id=".$categories_row['ProductID']."' onclick='return window.confirm(\"Do you really want to delete this product ?\")' class='links'>Delete</a></td> </tr>"; $i++; } } else { $content .= " <tr valign='middle' height='30'> <td colspan='10' class='message' align='center'>No Products Present</td> </tr>"; } $content .= "</table></div><br>"; break; } return $content; } function category($catid=0) { global $db; $categories_sql = "SELECT * FROM ".CATEGORY_TABLE." WHERE 1 ORDER BY CatName ASC"; $categories_result = $db->query($categories_sql); $categories = '<select name="cat_id" id="cat_id">'; if($categories_result->size()>0) { while ($categories_row = $categories_result->fetch()) { $cat_id = $categories_row['CatID']; $cat_name = $categories_row['CatName']; ($cat_id==$catid) ? $selected='selected' : $selected=''; $categories .= "<option value='$cat_id' $selected>$cat_name</option>"; } } $categories .= '</select>'; return $categories; } function addProduct() { global $db; $name = GetSQLValueString($_POST['name'],'text'); $description = GetSQLValueString($_POST['description'],'text'); $cat_id = GetSQLValueString($_POST['cat_id'],'text'); $price = GetSQLValueString($_POST['price'],'text'); $products_sql = "INSERT INTO ".PRODUCT_TABLE."(CatID,ProductName,ProductDesc,ProductPrice) VALUES($cat_id,$name,$description,$price)"; $products_result = $db->query($products_sql); $products_id = $products_result->insertID(); if($_FILES['image']['size']>0 && strstr($_FILES['image']['type'],'image')) { $tmpname = $_FILES['image']['tmp_name']; $filename = $_FILES['image']['name']; $filenames = explode('.',$filename); $ext = $filenames[count($filenames)-1]; copy($tmpname,"../images/product/$products_id.$ext"); $ext = GetSQLValueString($ext,'text'); $products_sql = "UPDATE ".PRODUCT_TABLE." SET ProductImage=$ext WHERE ProductID='$products_id'"; $db->query($products_sql); } return header("Location: products.php?action=view&msg=Product Details Added"); exit; } function updateProduct() { global $db; $products_id = $_GET['id']; $name = GetSQLValueString($_POST['name'],'text'); $description = GetSQLValueString($_POST['description'],'text'); $cat_id = GetSQLValueString($_POST['cat_id'],'text'); $price = GetSQLValueString($_POST['price'],'text'); $products_sql = "UPDATE ".PRODUCT_TABLE." SET CatID=$cat_id,ProductName=$name,ProductDesc=$description,ProductPrice=$price WHERE ProductID='$products_id'"; $db->query($products_sql); if($_FILES['image']['size']>0 && strstr($_FILES['image']['type'],'image')) { $product_sql = "SELECT * FROM ".PRODUCT_TABLE." WHERE id=".$_GET['id']; $product_result = $db->query($product_sql); $product_row = $product_result->fetch(); @unlink('../images/'.$product_row['id'].'.'.$product_row['image']); $tmpname = $_FILES['image']['tmp_name']; $filename = $_FILES['image']['name']; $filenames = explode('.',$filename); $ext = $filenames[count($filenames)-1]; copy($tmpname,"../images/product/$products_id.$ext"); $ext = GetSQLValueString($ext,'text'); $products_sql = "UPDATE ".PRODUCT_TABLE." SET ProductImage=$ext WHERE ProductID='$products_id'"; $db->query($products_sql); } return header("Location: products.php?action=view&msg=Product Details Updated"); exit; } function deleteProduct($pid=0,$cid=0) { global $db; if($cid!=0 && $pid==0) { $products_sql = "SELECT * FROM ".PRODUCT_TABLE." WHERE CatID='$cid'"; $products_result = $db->query($products_sql); if($products_result->size()>0) { while ($products_row = $products_result->fetch()) { $pid .= ",".$products_row['ProductID']; } } } $product_sql = "SELECT * FROM ".PRODUCT_TABLE." WHERE ProductID IN ($pid)"; $product_result = $db->query($product_sql); while($product_row = $product_result->fetch()) { @unlink('../images/product/'.$product_row['ProductID'].'.'.$product_row['ProductImage']); } $products_sql = "DELETE FROM ".PRODUCT_TABLE." WHERE ProductID IN ($pid)"; $db->query($products_sql); return header("Location: products.php?action=view&msg=Product Deleted"); exit; } ?>
  7. right, but im assured these are correct and was told to just unzip and connect to the database and it will work. Its working on there computer. So how do i change this? im a novice!
  8. Hi, Im getting two errors coming from the admin site of the website. Products.php and catergories.php Fatal error: Call to undefined function products() in C:\wamp\www\cart\admin\products.php on line 21 Fatal error: Call to undefined function categories() in C:\wamp\www\cart\admin\categories.php on line 23 I have also added the site as a zip file if you need the additional files! Categories.php <?php // Include MySQL class require_once('../inc/mysql.class.php'); // Include database connection require_once('../inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Include functions require_once('inc/category.inc.php'); // Include functions require_once('inc/product.inc.php'); // Start the session session_start(); if(!isset($_SESSION['AdminID'])) { return header("location: myaccount.php?action=login"); exit; } $array['categories'] = 'selected'; siteHeader($array); echo categories(); siteFooter(); ?> products.php <?php // Include MySQL class require_once('../inc/mysql.class.php'); // Include database connection require_once('../inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Include functions require_once('inc/product.inc.php'); // Start the session session_start(); if(!isset($_SESSION['AdminID'])) { return header("location: myaccount.php?action=login"); exit; } $array['products'] = 'selected'; siteHeader($array); echo products(); siteFooter(); ?> [attachment deleted by admin]
  9. function products() is defined in product.inc.php
  10. Still getting errors... not sure whats happening
  11. Hi Im getting this error on my web page : Fatal error: Call to undefined function products() in C:\wamp\www\cart\admin\products.php on line 23 <?php // Include MySQL class require_once('../inc/mysql.class.php'); // Include database connection require_once('../inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Include functions require_once('inc/product.inc.php'); // Start the session session_start(); if(!isset($_SESSION['AdminID'])) { return header("location: myaccount.php?action=login"); exit; } $array['products'] = 'selected'; siteHeader($array); echo products(); siteFooter(); ?>
  12. would this be under the following? ;;;;;;;;;;;;;;;;;;;;;;;;; ; Paths and Directories ; ;;;;;;;;;;;;;;;;;;;;;;;;; ; UNIX: "/path1:/path2" ;include_path = ".:/php/includes" ; ; Windows: "\path1;\path2" ;include_path = ".;c:\wamp\www\cart" <----- changed, this correct???
  13. Hi New to php so need some direction on how to set the php_include_path. Im trying to setup the following, from a tutorial. Also I am using WAMP. These scripts use a require statement that calls "Cart.php" In order for this to work properly, you need to set PHP's include path so that it will look in the Cart root directory. If your web server allows .htaccess files to override Apache config file settings, then place a file called .htaccess in you Cart root directory with the following line: php3_include_path /path/to/Cart If you cannot override Apache config file settings through .htaccess, then you can place the above line in your web server's directive in the Apache config files. For PHP4, this may be changed to "php4_include_path" or "php_include_path" - I'm not sure as PHP4 is still in beta at the time of this writing. If you use a web server other than Apache, you will need to check your web server's documentation for details. If you can't do either of those, create a PHP script which contains the following line: <? phpinfo(); ?> When you view that script in a web browser, you will see a directive called "include_path" in the Configuration table. Place the Cart.php file in one of the directories listed. If you can't make anything work, change the require(...) statement in the files of the admin directory to read: require("../Cart.php");
  14. im sorry, im new to the language and finding it hard to understand what info you require.
  15. Templates are not showing on the index.php, I get the following templatedir/header.php"); ?> Hello and welcome to MyMarket! This is the homepage, web masters, use this area: * Provide a basic map of the site * Advertise your on-sale items * Welcome customers to your site * Do useful things To begin shopping, go to the shopping page or buy the on-special items to your right. Your shopping cart is always visible on the left side of your screen. Click it to edit the contents of your basket or to check out. templatedir/footer.php"); ?> Here is the code for the index.php <? /* index.php (c) 2000 Ying Zhang (ying@zippydesign.com) * * TERMS OF USAGE: * This file was written and developed by Ying Zhang (ying@zippydesign.com) * for educational and demonstration purposes only. You are hereby granted the * rights to use, modify, and redistribute this file as you like. The only * requirement is that you must retain this notice, without modifications, at * the top of your source code. No warranties or guarantees are expressed or * implied. DO NOT use this code in a production environment without * understanding the limitations and weaknesses pretaining to or caused by the * use of these scripts, directly or indirectly. USE AT YOUR OWN RISK! */ /****************************************************************************** * MAIN *****************************************************************************/ include("application.php"); $DOC_TITLE = "MyMarket Home"; include("$CFG->templatedir/header.php"); ?> <table width=100%> <tr valign="top"> <td class=normal> Hello and welcome to MyMarket! This is the homepage, web masters, use this area: <ul class=normal> <li>Provide a basic map of the site</li> <li>Advertise your on-sale items</li> <li>Welcome customers to your site</li> <li>Do useful things</li> </ul> <p>To begin shopping, <a href="shopping/">go to the shopping page</a> or buy the on-special items to your right. Your shopping cart is always visible on the left side of your screen. Click it to edit the contents of your basket or to check out. </td> </tr> </table> <? include("$CFG->templatedir/footer.php"); ?> Here is the code for the application.php which contains the settings of the location of the templates etc <? /* $RCSfile: application.php,v $ (c) 2000 Ying Zhang (ying@zippydesign.com) * * $Revision: 1.7 $ * $Date: 2002/09/23 17:31:17 $ * $Author: yingz $ * * TERMS OF USAGE: * This file was written and developed by Ying Zhang (ying@zippydesign.com) * for educational and demonstration purposes only. You are hereby granted the * rights to use, modify, and redistribute this file as you like. The only * requirement is that you must retain this notice, without modifications, at * the top of your source code. No warranties or guarantees are expressed or * implied. DO NOT use this code in a production environment without * understanding the limitations and weaknesses pretaining to or caused by the * use of these scripts, directly or indirectly. USE AT YOUR OWN RISK! */ /* turn on verbose error reporting (15) to see all warnings and errors */ error_reporting(15); /* define a generic object */ class object {}; $CFG = new object; /* database configuration */ $CFG->dbhost = "localhost"; $CFG->dbname = "mymarket"; $CFG->dbuser = "myuser"; $CFG->dbpass = "mypassword"; /* directory configuration, if all your mymarket files are in one directory * you probably only need to set the wwwroot variable. valid examples are: * * $CFG->wwwroot = "http://myserver.com/mymarket"; * $CFG->wwwroot = "http://localhost/mymarket"; * * do not include the trailing slash. dirroot is the physical path on your * server where mymarket can find it's files. for more security, it is * recommended that you move the libraries and templates ($CFG->libdir * and $CFG->templatedir) outside of your web directories. */ $CFG->wwwroot = "http://localhost/mymarket"; $CFG->dirroot = “C:/wamp/www/mymarket”; $CFG->templatedir = "$CFG->dirroot/templates"; $CFG->libdir = "$CFG->dirroot/lib"; $CFG->imagedir = "$CFG->wwwroot/images"; $CFG->icondir = "$CFG->imagedir/icons"; $CFG->bannerdir = "$CFG->imagedir/banners"; $CFG->support = "support@mymarket.org"; $CFG->version = "1.71"; $CFG->sessionname = "mymarket"; /* extended configuration */ $CFG->showsponsor = true; // enabled banner advertising $CFG->currency = "$"; $CFG->currencyfirst = true; // show the currency symbol before the price tag /* define database error handling behavior, since we are in development stages * we will turn on all the debugging messages to help us troubleshoot */ $DB_DEBUG = true; $DB_DIE_ON_FAIL = true; /* load up standard libraries */ require("$CFG->libdir/stdlib.php"); require("$CFG->libdir/dblib.php"); require("$CFG->libdir/mymarket.php"); require("$CFG->libdir/cart.php"); /* setup some global variables */ $ME = qualified_me(); /* start up the sessions, to keep things simple we just have two * variables, USER containing user information and CART containing * the user's shopping cart. */ ini_set("session.name", $CFG->sessionname); session_start(); session_register("USER"); session_register("CART"); /* initialize the USER object if necessary */ if (! isset($_SESSION["USER"])) { $_SESSION["USER"] = array(); } /* initialize the CART object if necessary */ if (! isset($_SESSION["CART"])) { $_SESSION["CART"] = new Cart; } $USER = &$_SESSION["USER"]; $CART = &$_SESSION["CART"]; /* connect to the database */ db_connect($CFG->dbhost, $CFG->dbname, $CFG->dbuser, $CFG->dbpass); ?>
  16. Hi im having trouble displaying the templates on my index.php. All im getting is the following displayed. templatedir/header.php"); ?> Hello and welcome to MyMarket! This is the homepage, web masters, use this area: * Provide a basic map of the site * Advertise your on-sale items * Welcome customers to your site * Do useful things To begin shopping, go to the shopping page or buy the on-special items to your right. Your shopping cart is always visible on the left side of your screen. Click it to edit the contents of your basket or to check out. templatedir/footer.php"); ?> here is the index.php code <? include("application.php"); $DOC_TITLE = "MyMarket Home"; include("$CFG->templatedir/header.php"); ?> <table width=100%> <tr valign="top"> <td class=normal> Hello and welcome to MyMarket! This is the homepage, web masters, use this area: <ul class=normal> <li>Provide a basic map of the site</li> <li>Advertise your on-sale items</li> <li>Welcome customers to your site</li> <li>Do useful things</li> </ul> <p>To begin shopping, <a href="shopping/">go to the shopping page</a> or buy the on-special items to your right. Your shopping cart is always visible on the left side of your screen. Click it to edit the contents of your basket or to check out. </td> </tr> </table> <? include("$CFG->templatedir/footer.php"); ?> here is the application.php which holds the configuration settings $CFG->wwwroot = "http://localhost/mymarket"; $CFG->dirroot = "/mymarket"; $CFG->templatedir = "$CFG->dirroot/templates"; $CFG->libdir = "$CFG->dirroot/lib"; $CFG->imagedir = "$CFG->wwwroot/images";
  17. got this error now resource(11) of type (mysql link persistent) Fatal error: Call to a member function query() on a non-object in C:\wamp\www\website\order_fns.php on line 33
  18. I'm getting this error Fatal error: Call to a member function autocommit() on a non-object in C:\wamp\www\website\order_fns.php on line 26 <?php function process_card($card_details) { // connect to payment gateway or // use gpg to encrypt and mail or // store in DB if you really want to return true; } function insert_order($order_details) { // extract order_details out as variables extract($order_details); // set shipping address same as address if((!$ship_name) && (!$ship_address) && (!$ship_city) && (!$ship_state) && (!$ship_zip) && (!$ship_country)) { $ship_name = $name; $ship_address = $address; $ship_city = $city; $ship_state = $state; $ship_zip = $zip; $ship_country = $country; } $conn = db_connect(); // we want to insert the order as a transaction // start one by turning off autocommit $conn->autocommit(FALSE); // insert customer address $query = "select customerid from customers where name = '".$name."' and address = '".$address."' and city = '".$city."' and state = '".$state."' and zip = '".$zip."' and country = '".$country."'"; $result = $conn->query($query); if($result->num_rows>0) { $customer = $result->fetch_object(); $customerid = $customer->customerid; } else { $query = "insert into customers values ('', '".$name."','".$address."','".$city."', '".$state."','".$zip."','".$country."')"; $result = $conn->query($query); if (!$result) { return false; } } $customerid = $conn->insert_id; $date = date("Y-m-d"); $query = "insert into orders values ('', '".$customerid."', '".$_SESSION['total_price']."', '".$date."', '".PARTIAL."', '".$ship_name."', '".$ship_address."', '".$ship_city."', '".$ship_state."', '".$ship_zip."', '".$ship_country."')"; $result = $conn->query($query); if (!$result) { return false; } $query = "select orderid from orders where customerid = '".$customerid."' and amount > (".$_SESSION['total_price']."-.001) and amount < (".$_SESSION['total_price']."+.001) and date = '".$date."' and order_status = 'PARTIAL' and ship_name = '".$ship_name."' and ship_address = '".$ship_address."' and ship_city = '".$ship_city."' and ship_state = '".$ship_state."' and ship_zip = '".$ship_zip."' and ship_country = '".$ship_country."'"; $result = $conn->query($query); if($result->num_rows>0) { $order = $result->fetch_object(); $orderid = $order->orderid; } else { return false; } // insert each book foreach($_SESSION['cart'] as $isbn => $quantity) { $detail = get_book_details($isbn); $query = "delete from order_items where orderid = '".$orderid."' and isbn = '".$isbn."'"; $result = $conn->query($query); $query = "insert into order_items values ('".$orderid."', '".$isbn."', ".$detail['price'].", $quantity)"; $result = $conn->query($query); if(!$result) { return false; } } // end transaction $conn->commit(); $conn->autocommit(TRUE); return $orderid; } ?>
  19. Hi Im getting the following error on show_cart.php Notice: Undefined index: cart in C:\wamp\www\chapter25\show_cart.php on line 39 <?php include ('book_sc_fns.php'); // The shopping cart needs sessions, so start one session_start(); @ $new = $HTTP_GET_VARS['new']; if($new) { //new item selected if(!isset($HTTP_SESSION_VARS['cart'])) { $HTTP_SESSION_VARS['cart'] = array(); $HTTP_SESSION_VARS['items'] = 0; $HTTP_SESSION_VARS['total_price'] ='0.00'; } if(isset($HTTP_SESSION_VARS['cart'][$new])) $HTTP_SESSION_VARS['cart'][$new]++; else $HTTP_SESSION_VARS['cart'][$new] = 1; $HTTP_SESSION_VARS['total_price'] = calculate_price($HTTP_SESSION_VARS['cart']); $HTTP_SESSION_VARS['items'] = calculate_items($HTTP_SESSION_VARS['cart']); } if(isset($_POST['save'])) { foreach ($_SESSION['cart'] as $isbn => $qty) { if($_POST[$isbn] == '0') { unset($_SESSION['cart'][$isbn]); } else { $_SESSION['cart'][$isbn] = $_POST[$isbn]; } } $_SESSION['total_price'] = calculate_price($_SESSION['cart']); $_SESSION['items'] = calculate_items($_SESSION['cart']); } do_html_header("Your shopping cart"); if(($_SESSION['cart']) && (array_count_values($_SESSION['cart']))) { display_cart($_SESSION['cart']); } else { echo "<p>There are no items in your cart</p><hr/>"; } $target = "index.php"; // if we have just added an item to the cart, continue shopping in that category if($new) { $details = get_book_details($new); if($details['catid']) $target = 'show_cat.php?catid='.$details['catid']; } display_button($target, 'continue-shopping', 'Continue Shopping'); // use this if SSL is set up // $path = $HTTP_SERVER_VARS['PHP_SELF']; // $server = $HTTP_SERVER_VARS['SERVER_NAME']; // $path = str_replace('show_cart.php', '', $path); // display_button('https://'.$server.$path.'checkout.php', //'go-to-checkout', 'Go To Checkout'); // if no SSL use below code display_button('checkout.php', 'go-to-checkout', 'Go To Checkout'); do_html_footer(); ?>
  20. Hi My index.php doesnt seem to be showing my templates. As I keep getting the following displayed on my index.php templatedir/header.php"); ?> templatedir/footer.php"); ?> Theres are my settings in my application.php $CFG->wwwroot = "http://localhost/mymarket"; $CFG->dirroot ="c:/wamp/www/mymarket" ; $CFG->templatedir = "$CFG-> dirroot/templates"; $CFG->libdir = "$CFG-> http://localhost/mymarket /lib"; $CFG->imagedir = "$CFG-> http://localhost/mymarket/images";
  21. Hi New to php and need some help setting up the physical path of my local server in a php file. Please could you give me an example of how i would do this. Here is the line of code. * dirroot is the physical path on your server dirroot = dirname(__FILE__);
  22. still getting the errors, could i send you the files for you to look over pls?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.