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
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 ...

Link to comment
Share on other sites

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";
}
}
?>

Link to comment
Share on other sites

Double check your form is a POST and has the names: login, username1, and password1

 

Display the query:

 

$sql = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'";

echo $sql;

$ress=mysql_query($sql) or die...

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.