Jump to content

MySQL and PHP Problem - Selecting a row WHERE username and password match


colleyboy

Recommended Posts

Hello I am having a little problem whilst coding a login system

 

I have done the "login part" but when it gets to the user_cp page I need to display the "user_id" field on the row where the "username" and "password" are a match.

 

 

 

 

 


<?php include "dbconnect.php" ?>

<p>USER CP</p>

<p><A HREF="logout.php">LOGOUT</A></p>

<?php

if (isset($_GET['username'])) {
$username = $_GET['username'];
}

if (isset($_GET['sessionid'])) {
$password = $_GET['sessionid'];

}

?>
<?php

$usersession = mysql_query("SELECT Username, Password FROM boom_users WHERE Username=$username && Password=$password") or 

die(mysql_error());
while($row = mysql_fetch_array($usersession))

{

echo $row['user_id'];

}



echo $username;
echo $password;

?>

 

BTW the username and password are displayed in the URL under "username" and "session_id".  I have echoed these to see if they display on page and they do.  The password is encrypted to not a problem.

 

I think the problem is in the part of:

 

 

"$usersession = mysql_query("SELECT Username, Password FROM boom_users WHERE Username=$username && Password=$password") or 
die(mysql_error()); while($row = mysql_fetch_array($usersession))"

 

It seems to check the table for a column which is the $username and $password from the url and what it should do check the table for where there is a match for username and password and then fetch the data in the column "user_id".

 

Your help is much appreciated and I am sure it is an easy fix as I have been behind the computer around 10 hours today lol :) .

 

Kind Regards,

Ian

As for your issue, aside from what Barand said, you aren't selecting the user_id field in the query, which means it won't be present in the results set . . .

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.