PDA

View Full Version : MySQL via VB interface code


Cloudrunner
06-01-2003, 03:39 PM
Using $DB_site How would I go about testing a table for a specific unique identifier and have the system return a true or false?

What I have so far (and it doesn't work):
(assuming dbase.test[id] is always a unique identifier within the table)



$testrecord = $DB_site->query("SELECT id FROM test WHERE testid = $testid");
if(!$testrecord){
echo "There is no record by this name!";
} else {
echo "Found the record!";
}



All I get is the VB warning stating that there is an error in the database when the record is not found. It works when the record is found though.

Any ideas how I could better test for this scenario? My brain is mushy from coding so long.

Thanks in advance!

Cloudrunner

filburt1
06-01-2003, 04:12 PM
What's the error?

Also, never use ! except for boolean values or values of only 1 or 0. On a related note, check out the === versus the == operator to see why I'm saying that.

Cloudrunner
06-01-2003, 08:20 PM
Got it!

Thanks Filburt. I appreciate it. Although the "===" is not the way that I went. I did the following:



$testrecord = $DB_site->query("SELECT * FROM test WHERE testid = '".$testid."'");
if($DB_site->num_rows($testrecord) == 1){
echo "Found the record!";
} else {
echo "There is no record by this name!";
}



So basically if the record exists, I'll be able to update it. If it doesn't then I can add it.

Anyways, Thanks for the kick start. It works now so far.

Ciao!

Cloud