Jump to content

login from mySQL database


fragman44

Recommended Posts

hello i am pretty new to php and mySQL and im sorry but i do not know what version of mysql i am using.

i am trying to retrieve the login info from a form that forwards the data to the page and compares it against the mySQL database. for some reason it will only say wrong password =[

sorry if i havent given enough info but im very new.

<?php
if(isset($_POST['login']))
{
$db_host = "localhost";
$db_user = "root";
$db_pwd = "thePass";
$db_name = "namestorage";

mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name) or die(mysql_error());



$username = $_POST['username1'];
$password = $_POST['password1'];

$ress=mysql_query("SELECT * FROM storagedata WHERE username='".$usernames."' AND password='".$passwords."'")
or die(mysql_error());

$rows=mysql_fetch_array($ress);


if(($rows["username"]==$username)&&($rows["password"]==$password))
	{ 
	   
	  echo "logged in";
}else {
echo "Incorrect Password or Username";
}
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/86084-login-from-mysql-database/
Share on other sites

You're using $usernames (plural) here:

 

...username='".$usernames."' AND ...

 

 

And only using $username (singular) here:

 

...$rows["username"]==$username)&&(...

 

 

Same problem with $passwords and $password. Modify the query to use the singular variable names.

 

 

FYI - There's no reason to do the exact check in PHP "if" statement because you're already doing the same thing in the SQL query itself. Just do after the fetch:  if ($rows) { echo "logged in"; } else ...

well i re-did the whole database and changed the code around to the best i could but still no luck..

<?php
if(isset($_POST['login']))
{
$db_host = "localhost";
$db_user = "root";
$db_pwd = "steveosb";
$db_name = "logins";

mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name) or die(mysql_error());



$username = $_POST['username1'];
$password = $_POST['password1'];

$ress=mysql_query(" SELECT * FROM users WHERE username='$username' AND password='$password' ")
or die(mysql_error());

if ($rows=mysql_fetch_array($ress)){

echo "logged in";
}else {
echo "Incorrect Password or Username";
}
}
?>

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.