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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL Query Problem 1

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
As I don't know PHP or MySQL very well, I've been working through the text "Practical PHP and MySQL: Building 8 Dynamic Web Applications" this weekend. Everything was going well until I began working on the shopping cart application.

Here is the code (which matches the book character-for-character) and the error I receive when loading the page:

Code:
<h1>Product Categories</h1>
<ul>
<?php

    $catsql = "SELECT * FROM categories;";
    $catres = mysql_query($catsql);
   
    while($catrow = mysql_fetch_assoc($catres))
    {
        echo "<li><a href='" . $config_basedir . "/products.php?id=" . $catrow['id'] . "'>" . $catrow['name'] . "</a></li>";
    }

?>
</ul>

The error I get on loading the main page is:

Code:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\[URL unfurl="true"]www\shoppingcart\bar.php[/URL] on line 8

I've checked the other sites the author builds in the text and, other than variable naming, the logic is exactly the same ... so I'm guessing that I'm missing something. Since I don't want to go any further until I'm sure it's working (easier to debug now rather than later) I'm asking for any thoughts/comments on the above.

Thanks in advance.

Tom

P.S. Cross posted this in the php forum since I'm not sure exactly where the error lies.


"My mind is like a steel whatchamacallit ...
 
Follow-on information:

Here is the table structure of the categories table:

Code:
id 	tinyint(4) 	
name 	varchar(20)

Here is a query and results from that query to show what is in the table:

Code:
SELECT COUNT( * ) AS `Rows` , `name`
FROM `categories`
GROUP BY `name`
ORDER BY `name`
LIMIT 0 , 30
	   
Rows 	name
1 	Beverages
1 	Cakes

Tnx again.

Tom

"My mind is like a steel whatchamacallit ...
 
Code:
SELECT * FROM categories
there is nothing wrong with this query

perhaps you are not executing this query, but some other query instead

in any case, it sounds like this is a php question

r937.com | rudy.ca
 
r937:

Yes, it was a php problem ... or, rather, a fat-finger-in-the-config-file problem caused by the loose nut in front of the keyboard.

Problem was a one character typo in the config file ... fixed, works ...

On the other hand, it was really good for me to work through the mysql and php issues and see better how things all fit together.

Thanks!

Tom

"My mind is like a steel whatchamacallit ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top