On Sat, 2009-05-16 at 10:37 +0100, Vernon St Croix wrote:
> Hi,
> 
> I am pretty new to PHP and I am trying to create a shopping cart. 
> 
> I keep on getting the below error when trying to show the shopping list. 
> 
> Any guidance that can be provided will be very much appreciated
> 
> Fatal error: Call to a member function query() on a non-object in 
> C:\wamp\www\draft\basket.php on line 36

> basket.php
> <?php 
>  include("mysql.class.php");
>  include ("header.php");
>  include ("mysql_connect.php");
>   include ("functions.php");
>  ?>
>  <div id="shopping">
> <h2>Rum Basket</h2>
> <?php
>     echo writeCart();
>     ?>
>  </div>
> <div id="rumlist">
>   <h2>Rum on Offer</h2>
>   <?php
>  
>  $sql= 'SELECT * FROM spirits BY id';
>   $result = $con->query($sql);
>  $output[]= '<ul>';
>  while ($row = $result->fetch()) {
>  $output[] = '<li>'.$row['name'].': &pound;'.$row['price'].'<br/><a 
> href="cart.php?action=add&id=
>   '.$row['id'].'">Add to Cart</a></li>';
>     }
>     $output[] = '</ul>';
>   echo join ('', $output);
>    ?>
>   </div>
> 
> </div>
> <?php
>  include("footer.html");
> 
> ?>
> 
> [snip][/snip]
> 
> Many Thanks
> 
> Vee
The code you are having the error on is expecting a mysqli object, but
you are using mysql, which doesn't create objects that you access
methods and properties of.

Change the $result line in basket.php to $result = mysql_query($sql) and
in your while loop change it to use $row = mysql_fetch_array($result)


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to