...

View Full Version : Login system help.



ole90
03-17-2007, 08:22 PM
So, when my user goes to log in, i'm pondering how i check that his username entered and password entered matches that in the db.

Heres what i wrote:


$query = "SELECT * FROM Members WHERE loginName='$username' AND password='$password'";
$result= mysql_query($query);
$check =mysql_num_rows($result);



if($check < 0) {
echo "Error: Username or password did not match! Please try again!";
}else{
echo "Successfully Logged in";

But that returns this error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/fantasy/public_html/loginprocess.php on line 15

Any help ?

Nightfire
03-17-2007, 08:26 PM
Your query probably failed. Echo the $query var and see if username and password are set

Forsaken
03-17-2007, 08:34 PM
the if isn't closed off either, but you should have gotten an error from that.

Changing

if($check < 0) to if($check <= 0) might help

how can the query return less than 0?


also try this

$query = mysql_query("SELECT * FROM `Members` WHERE `loginName` = '$username' AND `password` = '$password'");
$check =mysql_num_rows($query);

ole90
03-17-2007, 08:34 PM
They are set

ole90
03-17-2007, 08:47 PM
$query = mysql_query("SELECT * FROM `Members` WHERE `loginName` = '$username' AND `password` = '$password'");
$check =mysql_num_rows($query);


if($check <= 0) {
echo "Error: Username or password did not match! Please try again!";
}else{

Returns
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/fantasy/public_html/loginprocess.php on line 14
Error: Username or password did not match! Please try again!

Even though, when i echo the query it contains the right password and username

Nightfire
03-17-2007, 08:52 PM
Something's not right then.

Make sure your db field names are right. Make sure the info in the db is exactly how it is in your query. Are you connecting to the db? Is it the right db?

Forsaken
03-17-2007, 08:56 PM
$query = mysql_query("SELECT * FROM `Members` WHERE `loginName` = '$username' AND `password` = '$password'");
$check =mysql_num_rows($query);


echo(" SELECT * FROM `Members` WHERE `loginName` = '$username' AND `password` = '$password' ");



it should display SELECT * FROM `Members` Where .....

copy and paste that into your phpmyadmin sql, it should tell you whats wrong from there.

ole90
03-17-2007, 08:56 PM
i ran mysql_error(); and it said that my table doesn't exist x.x;

When i go to check in phpmyadmin it is there in front of my eyes, and only 10 seconds ago i had matched up results from that table.

I seriously believe my server i'm on could be messed up, unless it is my coding.

Forsaken
03-17-2007, 08:57 PM
I doub't it, maybe you have member, but not Member, and its possible you might have members or even Members and your not noticing the small mistake

Nightfire
03-17-2007, 08:58 PM
Have you called it Members, or members? It's case sensitive

ole90
03-17-2007, 09:09 PM
Yeah, you guys were right xD

Now, new errors to do with the next part of the script.


if($check <= 0) {
echo "Error: Username or password did not match! Please try again!";
}else{
echo "Successfully Logged in";
session_register("username", $username);
session_register("password", $password);
echo "<br><br>Welcome, ". $username ." please go back to the <a href='main.php'>main page</a>";
}

?>

Now i'm getting a few errors:

Successfully Logged in
Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/fantasy/public_html/functions.php:14) in /home/fantasy/public_html/loginprocess.php on line 22


Welcome, Ice please go back to the main page
Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

Forsaken
03-17-2007, 09:11 PM
I would do

$_SESSION['username'] = $username; etc...


heres a link:
http://us3.php.net/session_register

ole90
03-17-2007, 09:19 PM
Works like a treat now! Thanks both of you for your help!

Inigoesdr
03-17-2007, 09:19 PM
Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/fantasy/public_html/functions.php:14) in /home/fantasy/public_html/loginprocess.php on line 22
You have to set the session variable before you output anything.

Nightfire
03-17-2007, 09:32 PM
You have to set the session variable before you output anything.

That's not quite right. You can set session variables anywhere, but you cannot start a session (session_start()) anywhere. session_start() has to be before anything is outputted

Inigoesdr
03-18-2007, 04:54 AM
That's not quite right. You can set session variables anywhere, but you cannot start a session (session_start()) anywhere. session_start() has to be before anything is outputted
Oops, I misspoke. :D That's what I intended to say^



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum