Hi,
I'm having a bit of a problem with all my query's that result in no match in my sql database. You see, I'm simply trying to check the database to see if a match exists. And if it does, do something. If not, do something else. But each time I check it and the match doesn't exist, it still does that something else, but it also spits out a warning...
"Warning: Unable to jump to row 0 on MySQL result index 2"
Here's the code I have so far after a bit of trial and error (this code half-way works, except it's spitting out the error):
// Connect to the database.
$db = connectDB();
$result = mysql_query("SELECT * FROM table WHERE fname='$fname' AND lname='$lname'", $db);
//if the match exists...
if(mysql_result($result,0,"fname") {
// ... do something ... //
} else {
// ... do something else ... //
}
and that if statement will actually go to the right one (do something or do something else) but it also gives me that darn warning at the top of my page. I've tried a few things in the past that don't seem to work, such as:
$rows = mysql_num_rows($result);
if($rows == 0) {
// the match isn't in the database //
} else {
// the match was found //
}
and I've also tried
$array = mysql_fetch_array($result);
if($array) {
// match not found //
} else {
// match found //
}
On top of that, I've also tried the not (!) operator in front of all those. The only one I've really gotten working out of all the code above is the first one I showed you, the mysql_result($result) one.
My query is working, I know that because I've tried:
echo $result;
right after the query and it prints out "2" ... Besides that evidence, I also believe the query is working fine because the if statement half-way works (except for the warning, of course) and it prints out the information I was looking for in the database, so the query's gotta be working.
It's doing this on all of my tests like that.. All I want it to be able to do is see if the match exists in the database, and do something depending on whether it's there or not, without having this warning trash the top of my page =)
So, if you have any ideas, I'd sure like to know what's in your head. This is my first time trying out PHP, and it's some pretty cool stuff fromn what I've seen so far, besides this warning message =)
Thanks a lot in advance for the help,
Troy