If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > when i add a second item to cart this gives error, but not in first add item

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-08-11, 09:07
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
when i add a second item to cart this gives error, but not in first add item

when i add a second item to cart this gives error, but not in first add item...can you debug class function, I use XAMPP
# MySQL 5.5.8
# PHP 5.3.5?

Notice: Undefined index: in C:\xampp\htdocs\Gosselin2006\Chapter.11\Chapter\Sh oppingCart.php on line 74

Unable to perform the query1.

Error code 1064: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 'WHERE productID=''' at line 1


// line 74:
$SQLstring = "SELECT * FROM ". $this->OrderTable[key($this->Orders)]." WHERE productID='".key($this->Orders)."';";

OrderTable[key($this->Orders)]=category[key(order Item)]=productTable
key($this->Orders)=key(order Item)

Code:
public function	showCart() {		
		if (empty($this->Orders))
		echo "<p>Your shopping cart is empty.</p>";
		else {
			echo "<table width='100%' border='1'>";
			echo "<tr><th>Product</th><th>Quantity</th><th>Price Each</th></tr>";
			$Total = 0;

			foreach($this->Orders as $Order) {
			    $SQLstring = "SELECT * FROM ". $this->OrderTable[key($this->Orders)]." WHERE productID='".key($this->Orders)."';"; // 74
				$QueryResult = @mysqli_query($this->DBConnect, $SQLstring) or die("<p>Unable to perform the query1.</p>"."<p>Error code ".mysqli_errno($this->DBConnect).":".mysqli_error($this->DBConnect))."</p>"; 
				$Row=mysqli_fetch_row($QueryResult);

				echo "<tr><td>{$Row[1]}</td>";
				echo "<td aligh='center'>$Order </td>";
				printf("<td aligh='center'>$%.2f</td></tr>",$Row[3]);
				
				$Total += $Row[3]*$Order;
				
				$SQLstring ="";
				next($this->Orders);
			} // end for each
			
			echo "<tr><td aligh='center' colspan='2'><strong>Your Shopping Cart contains ". count($this->Orders). " product(s).</strong></td>";
			printf("<td aligh='center'><strong>Total: $%.2f</strong></td>",$Total);			
			echo"</tr></table>";
		} // end if
	
	} // end function
Reply With Quote
  #2 (permalink)  
Old 03-08-11, 09:24
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Quote:
Originally Posted by lse123 View Post
Error code 1064: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 'WHERE productID=''' at line 1
please echo your query so we can see what it is after all the php "this->" shenanigans have finished constructing it
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-08-11, 10:48
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
Most likely your query does not find a table:

$SQLstring = "SELECT * FROM ". $this->OrderTable[key($this->Orders)]." WHERE productID='".key($this->Orders)."';";

If this->OrderTable[key($this->Orders)] returns nothing you will get a query as follows:

$SQLstring = "SELECT * FROM WHERE productID='1';";

If put that into sample code and this is what I get as error:

Code:
$res = mysql_query("SELECT * FROM WHERE id = 1;");
if(!$res) {
	die(mysql_error());
}
Executing this gives me:

Code:
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 'WHERE id = 1' at line 1
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #4 (permalink)  
Old 03-08-11, 12:25
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
Please note that I have 3 product categories with products [3 tables db]... well 1st added to cart correct meaning i guess not this the problem... when go to add SECOND ITEM TO CART from same or differ category that makes the error...

may execute many queries this way, more than one?
Reply With Quote
  #5 (permalink)  
Old 03-08-11, 12:30
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
As Rudy said, print off the SQL statement you are trying to execute and this will give you and us a better understanding of why it is failing at the database level. My posting was to show that it is quite likely that the table is not being populated in the SQL statement you are executing.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #6 (permalink)  
Old 03-08-11, 14:17
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
I attach

I attach
$this->Orders = quatity of product in array
$this->OrderTable[$ProdID] = table in db contains particular product info


Code:
SELECT * FROM olives WHERE productID='OLIVE003';
 Garlic Stuffed Olives 1  $8.99 

Notice: Undefined index: in C:\xampp\htdocs\Gosselin2006\Chapter.11\Chapter\ShoppingCart.php on line 74
SELECT * FROM WHERE productID='';

Unable to perform the query1.

Error code 1064: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 'WHERE productID=''' at line 1
after

Code:
$SQLstring = "SELECT * FROM ". $this->OrderTable[key($this->Orders)]." WHERE productID='".key($this->Orders)."';";
echo $SQLstring. "<br />";
$QueryResult = @mysqli_query($this->DBConnect, $SQLstring) or die("<p>Unable to perform the query1.</p>"."<p>Error code ".mysqli_errno($this->DBConnect).":".mysqli_error($this->DBConnect))."</p>";
Attached Files
File Type: zip Chapter.zip (6.8 KB, 2 views)
Reply With Quote
  #7 (permalink)  
Old 03-08-11, 14:27
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
your attached zip file is invalid or corrupted

what was the result of the echo? was it this --
Code:
SELECT * FROM WHERE productID='';
if so, i was right, your php code isn't filling in the table name properly
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 03-08-11, 15:54
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
I downloaded zip success and view contents.

I downloaded zip success and view contents.

seems when insert an item [first] this go to cart. second item appear the query but below appear another query with null table(cat) & product name...
Reply With Quote
  #9 (permalink)  
Old 03-14-11, 10:05
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
well can you debug, i guess is the loop
Reply With Quote
  #10 (permalink)  
Old 03-14-11, 10:08
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Quote:
Originally Posted by lse123 View Post
well can you debug, i guess is the loop
mysql doesn't have loops

perhaps what you want to do is ask the moderators to move your thread to the php forum
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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