darkknightgaury Posted September 8, 2007 Share Posted September 8, 2007 <?php $username='jose'; $password='javier'; $con = mysql_connect("localhost", "admin",""); mysql_select_db("usernames",$con); if (!$con) { die('Not connected : ' . mysql_error()); } $report = mysql_query("SELECT * FROM usernames where username like '$username%' and password like '$password%'");// i been debating whether i should include % while ($row = mysql_fetch_array($report)) { $correctusername = $row["username"];/* here since i ran the query in report it seems like i am being redundant bit but it make sense to clear the results with the report query before i read it, I dont know is my first username password code. */ $correctpassword= $row ["password"]; if($correctpassword==$password & $correctusername==$username) echo "The username and password has been verified."; } /*Yes. i realized this code is a begginers level dont bash me or talk down to me. */ ?> Link to comment https://forums.phpfreaks.com/topic/68514-php-login-username-and-password-verification/ Share on other sites More sharing options...
AdRock Posted September 8, 2007 Share Posted September 8, 2007 what's the question? Link to comment https://forums.phpfreaks.com/topic/68514-php-login-username-and-password-verification/#findComment-344388 Share on other sites More sharing options...
eZe616 Posted September 9, 2007 Share Posted September 9, 2007 I would do it something like this $sql = "SELECT * FROM usernames WHERE username='".$username."' AND password='".$password."' LIMIT 1"; // Since only 1 user should be able to have that combination $result = mysql_query($sql); if ($result) { $row = mysql_fetch_array($result); $correct_user = $row['username']; $correct_pass = $row['password']; if($correct_pass == $password && $correct_user == $username) { echo "The username and password has been verified."; } } Link to comment https://forums.phpfreaks.com/topic/68514-php-login-username-and-password-verification/#findComment-344503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.