PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
<?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...
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]
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.
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
}
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???
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
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.