I seem to have something strange going on with the execution of my php code; I hope someone can help.
One example:
I fetch info from a mysql database based on a field that is the primary key, not null. I know there is a match, because an error message will appear if there are no matches. After the mysql query, I have an include statement that produces a form, containing the data that was fetched. Most of the time, the form is returned containing the data. But sometimes the form is blank (without a "no matches" error message). Then, if I click on my refresh button, the form appears with the data in it. It "seems" that sometimes the code which generates the form is executing before the mysql query is complete.
Another example:
I have written code which generates a random password, encrypts it, stores the encrypted version, then sends the user the unencrypted password. Occasionally, the email that is sent does not contain the password, although the encrypted password is stored in the database (where it does no good, since I can't decrypt it to send the user the password she should have gotten in the email.) It "seems" that the code that sends the email is being executed before the password is being generated.
I am including a sample of the code for the first example above. I hope someone can see an obvious error that will explain this strange behavior. Thanks in advance.
(I know the first line below is true because the html form that is displayed contains $member_number in a hidden field, even when a blank form is returned.)
#=============================================================
if ($member_number != '') {
include ("/usr/home/test/inc/mysql_connect_members.php");
$query = "SELECT
TITLE,
FIRST_NAME,
MIDDLE_NAME,
LAST_NAME,
SUFFIX,
FROM MEMBERS WHERE MEMBER_NUMBER='".$member_number."'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results > 1) {
echo "There has been an error trying to retrieve the member info for member number $member_number; there was more than one match.";
exit;
}
elseif ($num_results == 0) {
echo "There has been an error trying to retrieve the member info for member number $member_number; there were no matches.";
exit;
}
$row = mysql_fetch_array($result);
$Title = htmlspecialchars(stripslashes($row["TITLE"]));
$First_Name = htmlspecialchars(stripslashes($row["FIRST_NAME"]));
$Middle_Initial = htmlspecialchars(stripslashes($row["MIDDLE_NAME"]));
$Last_Name = htmlspecialchars(stripslashes($row["LAST_NAME"]));
$Suffix = htmlspecialchars(stripslashes($row["SUFFIX"]));
}
include ("inc/inc_personal_info_form.php");
#=============================================================
#Following is the code contained in mysql_connect_members.php
#=============================================================
<?php
@ $db = mysql_pconnect("db123.host.com","username","password");
if (!$db)
{
echo "Sorry, the database is undergoing maintenance right now. Please try again later.";
exit;
}
mysql_select_db("dbname");
?>
#=============================================================
#Following is an example of the code contained in inc_personal_info_form.php
#=============================================================
<?
echo "<input type=hidden name=\"member_number\" value=\"$member_number\">\n";
?>
<table>
<tr>
<td>First Name</td><td>
<input type="text" name="First_Name" size="15"
<?
echo "value=\"$First_Name\">";
?>
</td></tr>
<tr><td>Last Name</td><td>
<input type="text" name="Last_Name" size="20"
<?
echo "value=\"$Last_Name\">";
?>
</td></tr>
</table>
<p>
<input type="submit" value="Continue">
</p>
</form>
Thanks for any help!
Diane