Blocking

wxdqz

New Member
I have a routine that verifies some information in a database before trying to add some records to prevent duplicates. See the code with comments below and then my question at the end...

//redirect is a function that calls header()
$killme = false;
$cn = mysql_connect("localhost","usename","password")
or redirect();
$db = mysql_select_db("dbname",$cn)
or redirect();
$sql = "select username from login where username = '" . $username . "'";
$res = mysql_query($sql,$cn)
or redirect();
$row = mysql_fetch_array($res);
//here is where it should bomb if username
//contains any text what-so-ever
if ($row["username"] != "") {
mysql_free_result($res);
redirect();
}
$sql = "select email from login where email = '" . $useremail . "'";
$res = mysql_query($sql,$cn)
or redirect();
$row = mysql_fetch_array($res);
//should die here if email is not empty
if ($row["email"] != "") {
mysql_free_result($res);
redirect();
}
$sql = "select phone from entries where phone = '" . $phone . "'";
$res = mysql_query($sql,$cn)
or redirect();
$row = mysql_fetch_array($res);
//should die here if phone != ""
if ($row["phone"] != "") {
mysql_free_result($res);
redirect("newentry.php3?f=dl");
end;
}
//None of the above bomb when they are supposed to.
//Only when you add an echo() call like the following:
echo($row["phone"]);
//does it die in the "if" section like it is supposed to.
//In the above code, if you add the echo() call after any of the "if" tests
//THEN it detects that the variable is empty.

My question: does PHP4 (possibly PHP3) not block on calls to MySQL even if the variable being asigned is used in a comparison, except under the condition that the variable is being returned to the browser with an output statement? In other words, does execution continue in the script and not wait on the SQL statement to return yet unless the variable will be used for output? If this should be the case, then how does one test for a blank field to determine which branch in code to take? Thank you all for this discussion group, I was at my ends until I came across it :)
 
Back
Top