Jump to content

PHP / MySQL Login Type issue


Ducky1

Recommended Posts

Hey guys, Im trying to create a simple login script that checks a username against an SQL database, and then compares the replied password with the password entered. Right now its compiling, but not returning an answer. Thanks for your help in advance.

 

<?php
$pass = $_POST['passwd'];
$user = $_POST['login'];
//echo $pass . $user;
$conn = mysql_connect("*", "*", "*");
if (!$conn ) 
{ 
echo "ERROR: Could not connect to the database."; 
}
$did_we_find_a_db_to_use = mysql_select_db("*");
if (!$did_we_find_a_db_to_use) 
{ 
echo "ERROR: Invalid database name."; 
}
$data = mysql_query("SELECT * FROM users WHERE 'name' = " . $user . ";");
while($info = mysql_fetch_array( $data ))
{
if($info['pass']==$pass) 
{
echo "Correct";
}

else
{ 
echo "Wrong";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/149947-php-mysql-login-type-issue/
Share on other sites

Well....

 

I am pretty sure you query is bad.

 

$data = mysql_query("SELECT * FROM users WHERE 'name' = " . $user . ";");

 

Should be:

mysql_query("SELECT * FROM users WHERE name = $user")

 

Here is example query from a page of mine:

	$query = "SELECT rank FROM ideas WHERE id=$delete_idea" or die (mysql_error());

 

The OR DIE is good will show you if mysql is messing up.

 

You could also put: error_reporting(E_ALL);

At the top of your page to force it to report every tiny error.

 

 

 

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.