It is currently Thu Mar 28, 2024 11:32 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: trouble SELECTing info from mySQL database table
PostPosted: Tue Jun 02, 2009 10:07 pm 
Newbie
Newbie

Joined: Tue Jun 02, 2009 10:00 pm
Posts: 3
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.";
         }




Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 03, 2009 12:12 am 
Newbie
Newbie

Joined: Tue Jun 02, 2009 10:00 pm
Posts: 3
Nevermind...my problem wasn't my code, but the fact that I used mysql_close() before the queries! It works great :P


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ]  Moderators: Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Hosting | Domains | Servers | Extras | Order | Support | Contacts | FreeHostia © 2011