Current location: Hot Scripts Forums » Programming Languages » PHP » Error 1064 in php call to mysql

Error 1064 in php call to mysql

Reply
  #31 (permalink)  
Old 05-13-09, 03:51 PM
KaizerBill KaizerBill is offline
New Member
 
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Gosselin's PHP Text Book

Hi Guys

I also picked this up. Thanks for the rectification of the code. I still find that the new code do not tender for adding multiple quantities of the same code. I will also sit down and sort that out, but there are quite a number of mistakes in this book by Gosselin and so far no where could I find any notifications by the author on the net. I will surely post something when I am finished.

Thanks for the input
KB

Quote:
Originally Posted by jaimenacach View Post
Hi, I'm new to the forum,

I have had the exact same issue as Vikki had, with every same EXACT problem throughout her posts.

I've taken the code from ShoppingCart.php in Post #23 by Job0107 and replaced it in my Shoppingcart.php. The shopping cart now works perfeclty. You can add items from any category, at any time, and the shopping cart ADDs them perfectly!

Thanks so much for the information you provided job0107!

I'm new to PHP programming too, and also have taken this challenge on my own, as I'm not part of any class, and don't get a grade!

It's too bad the author of our text book (Gosselin) did not review his code before printing his book. There are several errors.

In any case, if anyone needs the entire code from the various pages. Here they are. They are the pages that one creates for you Chapter Directory for Chapter 11 for the book called "PHP Programming with MySQL" by Don Gosselin.

Good luck to all the new students in the future!

ShoppingCart.php
PHP Code:
<?php
class ShoppingCart {
    private 
$DBConnect "";
    private 
$DBName "";
    private 
$TableName "";
    private 
$ItemCount 0;
     public 
$Orders = array();
     public 
$count 0;

    public function 
__construct() {
       
$this->DBConnect = @new mysqli("localhost""root""yourownpassword");
        if(
mysqli_connect_errno()) {
           die(
"<p>Unable to connect to the database server.</p><p>Error code ".mysqli_connect_errno().": ".mysqli_connect_error())."</p>";
        }
    }

    public function 
__destruct() {
       
$this->DBConnect->close();
    }

    public function 
setDatabase($Database) {
       
$this->DBName $Database;
       @
$this->DBConnect->select_db($this->DBName) or die("<p>Unable to select the database.</p><p>Error code ".mysqli_errno($this->DBConnect).": ".mysqli_error($this->DBConnect))."</p>";
    }

    public function 
setTable($Table) {
       
$this->TableName $Table;
    }

    public function 
getProductList() {
       
$SQLstring "SELECT * FROM $this->TableName";
       
$QueryResult $this->DBConnect->query($SQLstring) or die("<p>Unable to perform the query.</p><p>Error code ".mysqli_errno($this->DBConnect).": ".mysqli_error($DBConnect))."</p>";
       echo 
"<table width='100%' border='1'><tr><th>Product</th><th>Description</th><th>Price Each</th><th>Select Item</th></tr>";
       
$Row $QueryResult->fetch_row();
       while(
$Row) {
          echo 
"<tr><td style='padding-left:5px;'>{$Row[1]}</td><td style='padding-left:5px;'>{$Row[2]}</td>";
          
printf("<td align='center'>$%.2f</td>"$Row[3]);
          echo 
"<td align='center'><a href='ShowCart.php?PHPSESSID=".session_id()."&operation=addItem&productID=".$Row[0]."'>Add</a></td></tr>";
          
$Row $QueryResult->fetch_row();
       }
       echo 
"</table>";
    }

    public function 
addItem() {
       
$ProdID $_GET["productID"];
       for(
$i=0;$i<count($this->Orders);$i++) {
          if(
$this->Orders[$i][0]==$ProdID) {
             exit(
"<div style='width:385px;padding:5px;border:2px solid #ff0000;color:#cc0000;font-zixe:20px;font-weight:bold;'>You already selected that item!  Please choose a category.</div>");
          }
       }
       
$this->Orders[$this->ItemCount][0] = $ProdID;
       
$this->Orders[$this->ItemCount][1] = $this->TableName;
       
$this->ItemCount++;
    }

    public function 
__wakeup() {
       
$this->DBConnect = @new mysqli("localhost""root""yourownpassword");
       if(
mysqli_connect_errno()) {
          die(
"<p>Unable to connect to the database server.</p><p>Error code ".mysqli_connect_errno().": ".mysqli_connect_error())."</p>";
       }
       @
$this->DBConnect->select_db($this->DBName) or die("<p>Unable to select the database.</p><p>Error code ".mysqli_errno($this->DBConnect).": ".mysqli_error($this->DBConnect))."</p>";
    }

    public function 
showCart() {
       
$sw 0;
       for(
$i=0;$i<count($this->Orders);$i++) {
          
$Order $this->Orders[$i];
          
$Table_Name $Order[1] ? $Order[1] : "";
          
$ProdID $Order[0] ? $Order[0] : "";
          
$OrderQTY 1;
          if(
$Table_Name && $ProdID) {
             if(
$sw == 0) {
                echo 
"<table width='100%' border='1'><tr><th>Remove Item</th><th>Product</th><th>Quantity</th><th>Price Each</th></tr>";
                
$sw 1;
             }
             
$SQLstring "SELECT * FROM ".$Table_Name." WHERE productID='".$ProdID."'";
             
$QueryResult = @mysqli_query($this->DBConnect$SQLstring) or die("<p>Unable to perform the query.</p><p>Error code ".mysqli_errno($this->DBConnect).": ".mysqli_error($this->DBConnect))."</p>";
             
$Row mysqli_fetch_row($QueryResult);
             
$Total += $Row[3] * $OrderQTY;
             
$Total_total += $Total;
             
$Total 0;
             echo 
"<tr>
                   <td align='center'><a href='ShowCart.php?PHPSESSID="
.session_id()."&operation=removeItem&productID=".$Row[0]."'>Remove</a></td>
                   <td style='padding-left:10px;'>{$Row[1]}</td>
                   <td align='center'>$OrderQTY</td>"
;
                   
printf("<td align='center'>$%.2f</td></tr>"$Row[3]);
             
$found TRUE;
             
$this->count++;
          }
       }
       if(!
$found){echo "<table width='100%' border='1'><tr>";}
       else {
          
$link $Total_total "<a href='ShowCart.php?PHPSESSID=".session_id()."&operation=emptyCart'><strong>Empty Cart</strong></a>" "";
          echo 
"<tr><td align='center'>$link</td>";
       }
       echo 
"<td colspan='2'><strong>&nbsp;&nbsp;&nbsp;Your shopping cart contains ".$this->count." product(s).</strong></td>";
       
printf("<td align='center'><strong>Total: $%.2f</strong></td></tr>"$Total_total);
       echo 
"</table>";
       
$this->count 0;
    }

    public function 
removeItem() {
       
$ProdID $_GET['productID'];
       for(
$i=0;$i<count($this->Orders);$i++) {
          if(
$this->Orders[$i][0] == $ProdID) {
             
$this->Orders[$i][0] = "";
             
$this->Orders[$i][1] = "";
          }
       }
    }

    public function 
emptyCart() {
       for(
$i=0;$i<count($this->Orders);$i++) {
          
$this->Orders[$i][0] = "";
          
$this->Orders[$i][1] = "";
       }
    }
}
?>
ShowCart.php
PHP Code:
<?php
session_start
();
require_once(
"ShoppingCart.php");
if (!isset(
$_SESSION['curCart']))
    
header("location:GosselinGourmetGoods.php");
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gosselin Gourmet Goods</title>
<link rel="stylesheet" href="php_styles.css" type="text/css" />
</head>
<body>
<h1>Gosselin Gourmet Goods</h1>
<h2>Shop by Category</h2>
<p><a href="GosselinGourmetCoffees.php">Gourmet Coffees</a><br />
<a href="GosselinGourmetOlives.php">Specialty Olives</a><br />
<a href="GosselinGourmetSpices.php">Gourmet Spices</a></p>
<?php
$Cart 
unserialize($_SESSION['curCart']);
if (isset(
$_GET['operation'])) {
    if (
$_GET['operation'] == "addItem")
        
$Cart->addItem();
    if (
$_GET['operation'] == "removeItem")
        
$Cart->removeItem();
    if (
$_GET['operation'] == "emptyCart")
        
$Cart->emptyCart();
}
$Cart->showCart();
$_SESSION['curCart'] = serialize($Cart);
?>
</body>
</html>
GosselingGourmetCoffee.php
PHP Code:
<?php
session_start
();
require_once(
"ShoppingCart.php");
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gosselin Gourmet Goods</title>
<link rel="stylesheet" href="php_styles.css" type="text/css" />
</head>
<body>
<h1>Gosselin Gourmet Goods</h1>
<h2>Shop by Category</h2>
<p><a href="GosselinGourmetCoffees.php">Gourmet Coffees</a><br />
<a href="GosselinGourmetOlives.php">Specialty Olives</a><br />
<a href="GosselinGourmetSpices.php">Gourmet Spices</a></p>
<h2>Gourmet Coffees</h2>
<?php
$Database 
"gosselin_gourmet"
$Table "coffee";
if (isset(
$_SESSION['curCart']))
    
$Cart unserialize($_SESSION['curCart']);
else {
    if (
class_exists("ShoppingCart")) {
        
$Cart = new ShoppingCart();
        
$Cart->setDatabase($Database);
    }
    else
        exit(
"<p>The ShoppingCart class is not available!</p>");
}
$Cart->setTable($Table);
$Cart->getProductList();
$_SESSION['curCart'] = serialize($Cart);
?>
<p><a href='<?php echo "ShowCart.php?PHPSESSID=" session_id() ?>'>Show Shopping Cart</a></p>
</body>
</html>
thanks so much once again

Jaime Nacach
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #32 (permalink)  
Old 11-11-09, 06:02 PM
karotech karotech is offline
New Member
 
Join Date: Nov 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
I stumbled to this forum because I was having the same problem as Vikki, also I have the same textbook. I was testing the program on my local machine and ended up having exactly the same error message. Running out of options I decided to upload the program to my school remote server and the program works the way it should. So, in case someone else stumbles to this forum it seems that the problem lies in the way the config.ini in PHP is configured. Now, this is just my guess becuase I have not found out why it doesn't work on local machine. g/l -karo

Last edited by karotech; 11-11-09 at 06:05 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #33 (permalink)  
Old 11-23-09, 09:38 PM
SweetPea25 SweetPea25 is offline
New Member
 
Join Date: Nov 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Hi folks. Thank you all so much for going through all this code and the problems that ensued. I am also a PHP newbie taking a class and using this lousy book. The number of errors in the book are amazing.

I inputted all the code that's been posted in this forum and it works great. But the code that's left to place does not work. There's a checkout.php file to allow for checkout and then there are extra classes to add quantities to the orders. I'm using the code posted in KaizerBill's post above and below is the code for the checkout.php file as well as the extra code (that I can't get to work) to add one or remove one from the quantity chart that's part of the ShoppingCart.php file.

This is the checkout.php code:

Quote:
<?php
require_once("ShoppingCart.php");
session_start();
if (!isset($_SESSION['curCart']) && $_GET['operation'] != "checkout")
header("location:GosselinGourmetGoods.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Gosselin Gourmet Goods</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="php_styles.css" type="text/css" />
</head>
<body>
<h1>Gosselin Gourmet Goods</h1>
<?php
$Cart = unserialize($_SESSION['curCart']);
$Cart->setTable("myorders");
$Cart->checkout();
?>
<p><a href="GosselinGourmetGoods.php">Gosselin Gourmet Goods</a></p>
</body>
</html>
And this is the extra code to add one or remove one that originally appears in the ShoppingCart.php code from the book:

Quote:
public function addOne() {
$ProdID = $_GET['productID'];
$this->Orders[$ProdID] += 1;
}
public function removeOne() {
$ProdID = $_GET['productID'];
$this->Orders[$ProdID] -= 1;
if ($this->Orders[$ProdID] == 0)
$this->removeItem();
}
public function checkout() {
$ProdID = $_GET['productID'];
foreach($this->Orders as $Order) {
$SQLstring = "INSERT INTO " . $this->TableName . " VALUES('" . session_id() . "','" . key($this->Orders) . "','" . $this->OrderTable[key($this->Orders)] . "'," . $Order . ")";
$QueryResult = @mysqli_query($this->DBConnect, $SQLstring)
Or die("<p>Unable to perform the query.</p>"
. "<p>Error code " . mysqli_errno($this->DBConnect)
. ": " . mysqli_error($this->DBConnect)) . "</p>";
}
Can anyone help me figure out if I've got this written correctly? The added code goes towards the bottom of the ShoppingCart.php script under public function emptyCart()

Last edited by SweetPea25; 11-23-09 at 09:40 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Complex mysql sorting pb (Get cat_list from cids &pcids with 1 query, willing to pay) aqw PHP 1 06-23-05 07:02 PM
How to get PHP to input data into a MYSQL table? scl789 PHP 5 04-21-05 09:06 PM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 2 11-12-04 03:25 PM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 10-30-04 01:19 PM
PHP, MySQL, WML superman PHP 0 03-04-04 10:46 AM


All times are GMT -5. The time now is 08:38 AM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.