I am using the following code after connecting to the DB to verify user data, however there seems to be some sort of error on the query, as $numRows is apparently not assigned a value after mysql_num_rows().
The query is as follows: "SELECT * FROM apartmentcomplex WHERE Tenants = 'LAST, FIRST'"
When I try the query in phpMyAdmin it works fine, but not via this script.
Any help would be fantastic! Thanks in advance!
Code:
$nameLastFirst = $_POST["lastName"] . ", " . $_POST["firstName"];
$query = "SELECT * FROM $table WHERE Tenant = '$nameLastFirst'";
$result = mysql_query($query);
$numRows = mysql_num_rows($result);
if ($numRows > 0) //we have a match
{
while ($row = mysql_fetch_assoc($result))
{
$db_tenant = $row["Tenant"];
$db_email = $row["E-mail"];
preg_match("/([\d]+[A-Z]+$)|([A-Z]+[\d]+$)/", $row["Apartment"], $matches);
$db_apt = $matches[0];
}
//if username & password match
if ($nameLastFirst == $db_tenant && $_POST["email"] == $db_email && $_POST["aptNo"] == $db_apt)
{
echo "Thank you for submitting your credentials. Please give up to 24 hours to have"
. " your information added to the system. <br />";
}
else
{
/*LIST THE ITEMS THAT DO NOT MATCH*/
if ($nameLastFirst != $db_tenant)
{
//format names for echo
$_POST["firstName"] = strtolower($_POST["firstName"]);
$_POST["lastName"] = strtolower($_POST["lastName"]);
$_POST["firstName"][0] = strtoupper($_POST["firstName"][0]);
$_POST["lastName"][0] = strtoupper($_POST["lastName"][0]);
$nameLastFirst = $_POST["firstName"] . " " . $_POST["lastName"];
//change back to normal order for echo
$nameLastFirst = $_POST["firstName"] . " " . $_POST["lastName"];
echo $nameLastFirst . " was not found in the list of registered tenants for this complex."
. " If you feel this is in error, please contact your local manager or systems administrator.";
}
elseif ($_POST["email"] != $db_email)
{
//format names for echo
$_POST["firstName"] = strtolower($_POST["firstName"]);
$_POST["lastName"] = strtolower($_POST["lastName"]);
$_POST["firstName"][0] = strtoupper($_POST["firstName"][0]);
$_POST["lastName"][0] = strtoupper($_POST["lastName"][0]);
$nameLastFirst = $_POST["firstName"] . " " . $_POST["lastName"];
//change back to normal order for echo
$nameLastFirst = $_POST["firstName"] . " " . $_POST["lastName"];
$_POST["email"] = strtolower($_POST["email"]);
echo $_POST["email"] . "@byui.edu is not associated with " . $nameLastFirst . ". <br />";
}
elseif ($_POST["aptNo"] != $db_apt)
{
//format names for echo
$_POST["firstName"] = strtolower($_POST["firstName"]);
$_POST["lastName"] = strtolower($_POST["lastName"]);
$_POST["firstName"][0] = strtoupper($_POST["firstName"][0]);
$_POST["lastName"][0] = strtoupper($_POST["lastName"][0]);
$nameLastFirst = $_POST["firstName"] . " " . $_POST["lastName"];
//change back to normal order for echo
$nameLastFirst = $_POST["firstName"] . " " . $_POST["lastName"];
echo $nameLastFirst . " is not a registered tenant of apartment " . $_POST["aptNo"] . "<br />"
. "(If applicable, did you reverse the number-letter combination?) <br />";
}
}
}
else
{
//format names for echo
$_POST["firstName"] = strtolower($_POST["firstName"]);
$_POST["lastName"] = strtolower($_POST["lastName"]);
$_POST["firstName"][0] = strtoupper($_POST["firstName"][0]);
$_POST["lastName"][0] = strtoupper($_POST["lastName"][0]);
$nameLastFirst = $_POST["firstName"] . " " . $_POST["lastName"];
//change back to normal order for echo
$nameLastFirst = $_POST["firstName"] . " " . $_POST["lastName"];
echo $nameLastFirst . " was not found in the list of registered tenants for this complex."
. " If you feel this is in error, please contact your local manager or systems administrator.";
}