FreeHostia Forums https://forum.freehostia.com/ |
|
trouble SELECTing info from mySQL database table https://forum.freehostia.com/viewtopic.php?f=7&t=9954 |
Page 1 of 1 |
Author: | jedbee [ Tue Jun 02, 2009 10:07 pm ] |
Post subject: | trouble SELECTing info from mySQL database table |
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."; } |
Author: | jedbee [ Wed Jun 03, 2009 12:12 am ] |
Post subject: | |
Nevermind...my problem wasn't my code, but the fact that I used mysql_close() before the queries! It works great ![]() |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |