Page 1 of 2

unable to login even the data is inside the database!!

Posted: Sun Jul 01, 2007 8:17 am
by xiao_dolp
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i dont know why my do_login.php is not working....i not sure issit fetch array problem or rows problem....
here the code

Code: Select all

<?php 
session_start();

require('db.php');

// Get the variables
$user = $_POST['username'];
$password = md5($_POST['password']);


mysql_connect(MACHINE, USER, '');
mysql_select_db(DBNAME);

$sql = "SELECT * FROM user Where username = '$user' and password = '$password'";
$result = mysql_query($sql);

		
//$rows = mysql_num_rows($result);


if ($rows == 1)
//if (mysql_num_rows($result) == 1)
{
$_SESSION['username'] = $user;
	echo "Login sucessful, click "."<a href = '../user/index.php'>here</a>"." to proceed.";

}else if (($rows == 0) and ($user)){
	echo "Invaild password, click "."<a href = '../user/user.html'>here</a>"." to re-enter password";
} else if ((!$user) and ($row == 0))
{
	echo "Invaild User id, click "."<a href = '../user/user.html'>here</a>"." to re-enter username";
}
?>
but even if what i input in user.html have enter my database, when i login again, it will display invaild user id
i wonder what is wrong??? i change my code many time but i still duno wat cost the problem...

cn help??
thank


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Jul 01, 2007 8:22 am
by superdezign
$rows isn't set.

Change this:

Code: Select all

if ($rows == 1)
//if (mysql_num_rows($result) == 1)
Into this:

Code: Select all

if (mysql_num_rows($result) == 1)
Also, your code doesn't look at the session variables to check if you're logged in.

Posted: Sun Jul 01, 2007 8:25 am
by miro_igov
If you leave this //$rows = mysql_num_rows($result); commented the $rows == 1 always will be false. You should uncomment it.

Also this condition else if (($rows == 0) and ($user)){ does not mean the password is wrong. The username also could be wrong and $rows = 0. while ($user) always is true if you enter anything in the user name form field.

Posted: Sun Jul 01, 2007 8:31 am
by xiao_dolp
even after i change it will still show
Invaild password, click here to re-enter password

and i echo out what i enter, the password and username is correct as wat i type but it just cant call out frm my database.....

issit there are some code that i have to add in to this php file or other of my php hav cause the problem???

Posted: Sun Jul 01, 2007 8:37 am
by superdezign
superdezign wrote:your code doesn't look at the session variables to check if you're logged in.

Posted: Sun Jul 01, 2007 3:38 pm
by xiao_dolp
what is the code to look at the session variables to check if i am logged in??

sorry, i new to it....

Posted: Sun Jul 01, 2007 5:17 pm
by superdezign
Session variable aren't magic. After you set them, you have to check them.

Code: Select all

if(!isset($_SESSION['username'])) // Not logged in yet
{
    // Check for posted variables and attempt to login
}
else // Already logged in
{
    // Show the rest of the stuff here
}

Posted: Tue Jul 03, 2007 9:02 am
by xiao_dolp
i try to check the session as what you mention, but i still have login error.

i figure out that it might because there are something wrong with my xampp....

because when i click on xampp_start.exe it will display message

(OS 10048)Only one usage of each socket address(protocol/network address/port) is normally permitted. : make_sock: unable to listen for connections on address 0.0.0.0:443
no listening sockets available, shutting down
Unable to open logs

is it because of this problem that why i cnt connect to database even if my code is correct???

how to solve this problem???

Posted: Tue Jul 03, 2007 9:15 am
by superdezign
You're quick to assume the code is correct, yet I haven't heard of any debugging attempts. I'd blame the code before I blamed the installation.

Posted: Tue Jul 03, 2007 9:20 am
by xiao_dolp
because i try the code on my friends computer and it able to work well, so i think maybe is my application problem that cause the error....i not sure able that

Posted: Tue Jul 03, 2007 9:25 am
by superdezign
So, you think you aren't able to communicate with your database? Have you tested this claim with simple queries?

Posted: Tue Jul 03, 2007 9:36 am
by xiao_dolp
cause i try echo all everything one by one to see what is the error, and the website does not retrieve from my database even though there are data in my database.

what simple queries can i try???

Posted: Tue Jul 03, 2007 9:44 am
by superdezign

Code: Select all

$result = mysql_query("SHOW TABLES;");
while($data = mysql_fetch_row($result))
    print_r($data);

Posted: Tue Jul 03, 2007 9:59 am
by xiao_dolp
This is what it show

Code: Select all

Array ( [0] => route ) Array ( [0] => user ) Array ( [0] => users ) Invaild User id, click here to re-enter username
it display 0 even though there are something in my database

Posted: Tue Jul 03, 2007 3:53 pm
by feyd
It's not showing zero results. Those are the array indices in the individual results.