Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Statement erroring out

Status
Not open for further replies.

WilliamMute

Programmer
Jan 4, 2006
117
Hi all,

I have been having a Shopping cart problem in the PHP forum for few days now for history see( )

Now I have got to the state that I was told that my problem is more for the MYSQL forum. I would appreciate any help on the reason why I am getting this error on the following sql statement I am REALLY exhausted of ideas all I need is a shopping cart!


CODE
Code:
mysql_select_db($database_Connection, $Connection);

$query = "SELECT SUM(products.product_price * springrisecart.quantity) AS subtotal,
           SUM(subtotal) as total
            FROM springrisecart, products
             WHERE (springrisecart.session) = '$cart_id' AND
            (springrisecart.product_id) = 'products.id'";
 echo '<pre>';
echo $query;
echo '</pre>';
  $result = mysql_query($query, $Connection) or die(mysql_error()); 
  $row = mysql_fetch_assoc($result);
   return $row['total'];
  $Final = $result;


The Error that I am getting is:
Code:
SELECT SUM(products.product_price * springrisecart.quantity) AS subtotal,
             SUM(subtotal) as total
             FROM springrisecart, products
             WHERE (springrisecart.session) = 'aaeb4f91f7695b77b61fffb4b04fbfa3' AND
             (springrisecart.product_id) = 'products.id'

Unknown column 'subtotal' in 'field list'

Please help if you can...
 
You can't use SUM(subtotal) as 'subtotal' is an alias, not a field name. In any event, it doesn't make sense. If you leave out the "SUM(subtotal) as total" bit, you will get one record returned containing the price*quantity total; is that what you want?
 
Am not sure, I have tried what you said and this is what I am getting now.

Code:
SELECT SUM(products.product_price * springrisecart.quantity) AS subtotal,
             FROM springrisecart, products
             WHERE (springrisecart.session) = 'aaeb4f91f7695b77b61fffb4b04fbfa3' AND
            (springrisecart.product_id) = 'products.id'

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 'FROM springrisecart, products WHERE (springrisecart.session) = 'aae' at line 2

Thanks
 
Cheers guys!!!!! the query dosnt return any error now! the only question now is would it return the total for the session? ummmm am not sure. But thanks a million and a half!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top