Jump to content

basic user authentication error


newbienewbie

Recommended Posts

NEWBIE:

 

I want to authenticte the entered username with the password sttored in db. but when i enter correct username and password it gives me error

 

Query failed: Unknown column 'xyz' in 'where clause'

 

plz chk this query  $query = "SELECT pass FROM $my_table WHERE user=$col_value";

 

and following code

 

<?php
$mysql_host='localhost';
$mysql_user='xyz';
$mysql_password='xyz';
$my_database='xyz';
$my_table='users';

// Connecting, selecting database
$link = mysql_connect($mysql_host,$mysql_user, $mysql_password)
    or die('Could not connect: ' . mysql_error());

mysql_select_db($my_database) or die('Could not select database');

// Performing SQL query
$query = "SELECT user FROM $my_table";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
//echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) 
{
    //echo "\t<tr>\n";
    foreach ($line as $col_value) 
{
	 if ($col_value == $_REQUEST['username']) 
	 {
	   
	  $query = "SELECT pass FROM $my_table WHERE user=$col_value";
	  $result=mysql_query($query) or die('Query failed: ' . mysql_error());
	  echo $result;
 	   if ($result == $_REQUEST['password']) 
		{
		echo "Welcome";
		}
		else 
            {
		echo "\nInvalid Password";
		}

	 }
}

}    
//    echo "\t\t<td>$col_value</td>\n";
  //  }
  //  echo "\t</tr>\n";
//}
//echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>

 

 

Link to comment
Share on other sites

itsmeArry,

 

tried ur option, and received error

 

Resource id #4 Invalid PasswordResource id #5 Invalid PasswordResource id #6 Invalid

 

PasswordResource id #7 Invalid PasswordResource id #8 Invalid PasswordResource id #9

 

Invalid PasswordResource id #10 Invalid PasswordResource id #11 Invalid PasswordResource

 

id #12 Invalid PasswordResource id #13 Invalid PasswordResource id #14 Invalid

 

PasswordResource id #15 Invalid PasswordResource id #16 Invalid PasswordResource id #17

 

Invalid PasswordResource id #18 Invalid PasswordResource id #19 Invalid PasswordResource

 

id #20 Invalid PasswordResource id #21 Invalid PasswordResource id #22 Invalid

 

PasswordResource id #23 Invalid PasswordResource id #24 Invalid PasswordResource id #25

 

Invalid PasswordResource id #26 Invalid PasswordResource id #27 Invalid PasswordResource

 

id #28 Invalid PasswordResource id #29 Invalid PasswordResource id #30 Invalid

 

PasswordResource id #31 Invalid PasswordResource id #32 Invalid PasswordResource id #33

 

Invalid PasswordResource id #34 Invalid PasswordResource id #35 Invalid PasswordResource

 

id #36 Invalid PasswordResource id #37 Invalid PasswordResource id #38 Invalid

 

PasswordResource id #39 Invalid PasswordResource id #40 Invalid PasswordResource id #41

 

Invalid PasswordResource id #42 Invalid PasswordResource id #43 Invalid PasswordResource

 

id #44 Invalid PasswordResource id #45 Invalid PasswordResource id #46 Invalid

 

PasswordResource id #47 Invalid PasswordResource id #48 Invalid PasswordResource id #49

 

--------

PC Nerd,

 

form disapared. nothing shown in browser.

 

Link to comment
Share on other sites

Look wht you have here

 

$result=mysql_query($query) or die('Query failed: ' . mysql_error());
echo $result;
if ($result == $_REQUEST['password']) 
{
     echo "Welcome";
}
else 
{
     echo "\nInvalid Password";
}

 

usde this::

 

$result=mysql_query($query) or die('Query failed: ' . mysql_error());

while($row = mysql_fetch_array($result))
if ($row['password'] == $_REQUEST['password']) 
{
     echo "Welcome";
}
else 
{
     echo "\nInvalid Password";
}

 

 

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.