Jump to content

Check for database for name.


Err

Recommended Posts

I'm trying to check a database if the name inputed in a form matches one on a MySQL database. So far, I've got the first name in the database checked somehow with the code below, but it won't check the second name in the database against the second name inputed on the form, the script just falls through the if even though I type a valid name into it. Anyone know better code to do this with? I'm probably making it more complicated than it actually is.database name: membertable: personfield: fname

<?phpextract($_POST);$con = mysql_connect("localhost","username","password");if (!$con) {  die("<p>Could not connect: " .mysql_error(). "</p>");}mysql_select_db("member", $con);$result = mysql_query("SELECT * FROM person");if ($row = mysql_fetch_array($result)) {  if (($row['fname']) != ($fname)) {	echo "<p>Your name is not in the database.</p>";  }  else {	echo "<p>".$fname." is a valid member name.</p>";  }}?>
Link to comment
Share on other sites

Guest wishkie
I'm trying to check a database if the name inputed in a form matches one on a MySQL database. So far, I've got the first name in the database checked somehow with the code below, but it won't check the second name in the database against the second name inputed on the form, the script just falls through the if even though I type a valid name into it. Anyone know better code to do this with? I'm probably making it more complicated than it actually is.database name: membertable: personfield: fname
<?phpextract($_POST);$con = mysql_connect("localhost","username","password");if (!$con) {  die("<p>Could not connect: " .mysql_error(). "</p>");}mysql_select_db("member", $con);$result = mysql_query("SELECT * FROM person");if ($row = mysql_fetch_array($result)) {  if (($row['fname']) != ($fname)) {	echo "<p>Your name is not in the database.</p>";  }  else {	echo "<p>".$fname." is a valid member name.</p>";  }}?>
try to use this one bro!$result = mysql_query("SELECT * FROM person where 'fname' = '$fname'");$found = mysql_num_rows($result);if(!$found){echo "<p>Your name is not in the database.</p>"; }else{echo "<p>".$fname." is a valid member name.</p>"; }
Link to comment
Share on other sites

Sweet. Thanks man, I knew I was making it too hard. Though I to take off the single quotes around the fname after the WHERE, but I got it working.

Link to comment
Share on other sites

make sure that when the information if submitted, it is in the same format as what is in the databaseif you are looking for Mike, and the database has mike, YOU WILL not have a match.strtolower when you enter the information to the database, and again when you check for it.strtolower will chance all letter to small letterso if someone enters MiKe sMItHit will end up being mike smith either way you look for it, or submit it.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...