Results 1 to 10 of 10
  1. #1
    Join Date
    May 2007
    Posts
    139

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    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
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  4. #4
    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?

  5. #5
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    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
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  6. #6
    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 Attached Files

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    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...

  9. #9
    Join Date
    May 2007
    Posts
    139
    well can you debug, i guess is the loop

  10. #10
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •