I have been struggling with this for over a day now and thought I would post to see if someone could help me out. I basically have a form that passes variables through the url to a php script, that then queries the database and displays the results.
The problem I'm having is sometimes it works, and other times it results differently. Here's what I mean.
For error checking, I eliminated the use of the sql class and went to the basics...printing everything out to see what's going on. Here's the relevant code:
include("config.php");
// Connect to MySQL Server
$connection = mysql_connect($server, $username, $password) or DIE("Couldn't connect to MySQL Server");
// Select Database
mysql_select_db($database, $connection) or DIE("Couldn't Select Database");
$sql = "SELECT * FROM suspension_data WHERE year='".$_GET["year"]."' AND make='".$_GET["make"]."' AND model='".$_GET["model"]."'";
$queryIT = mysql_query($sql) or die(mysql_error());
print($sql) . "<br>\n";
$items = mysql_fetch_assoc($queryIT);
mysql_free_result($queryIT);
mysql_close($connection);
unset($queryIT);
echo "Items:<pre>" . print_r($items) . "</pre>\n";
When I print $sql, I always get the right query (meaning as I change the inputs in the form, the query changes properly). my $sql query looks like this:
SELECT * FROM suspension_data WHERE year='2002' AND make='YAMAHA' AND model='YZF 450 Quad'
The error I am occasionaly getting is this:
Warning: Invalid argument supplied for foreach() in E:\WEBSITES\changed\bla\functions.php on line 653
It's a valid argument when the query is working, it's just coming up invalid because $items simply returns "1" in the instances when I get this error rather than the array it should be returning.
I've tried closing the mysql connections, freeing the results, unsetting variables--all to no avail. I really have no idea what is going wrong and can only hope it's a simple fix.
Thanks,
Cgraz