niko-cola
03-22-2010, 02:06 AM
I can't make it work.
The table users has email and password fields.
Please help me.
<?php
// we must never forget to start the session
session_start();
$errorMessage = '';
function dbConnect()
{
global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
@mysql_connect(localhost, root, root) or error( mysql_error() );
mysql_select_db(database);
//sets encoding to utf8
mysql_query("SET NAMES utf8");
}
ob_start();
dbConnect();
$query="SELECT * FROM users WHERE email='$txtUserId' && password='$txtPassword'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if ($num==1) {
// the user id and password match,
// set the session
$_SESSION['basic_is_logged_in'] = true;
// after login we move to the main page
header('Location: b-main.php');
ob_end_flush();
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}
?>
<html>
<head>
<title>Basic Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
<?php
}
?>
<form method="post" name="frmLogin" id="frmLogin">
<table width="400" border="1" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="150">User Id</td>
<td><input name="txtUserId" type="text" id="txtUserId"></td>
</tr>
<tr>
<td width="150">Password</td>
<td><input name="txtPassword" type="password" id="txtPassword"></td>
</tr>
<tr>
<td width="150"> </td>
<td><input type="submit" name="btnLogin" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>
The table users has email and password fields.
Please help me.
<?php
// we must never forget to start the session
session_start();
$errorMessage = '';
function dbConnect()
{
global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
@mysql_connect(localhost, root, root) or error( mysql_error() );
mysql_select_db(database);
//sets encoding to utf8
mysql_query("SET NAMES utf8");
}
ob_start();
dbConnect();
$query="SELECT * FROM users WHERE email='$txtUserId' && password='$txtPassword'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if ($num==1) {
// the user id and password match,
// set the session
$_SESSION['basic_is_logged_in'] = true;
// after login we move to the main page
header('Location: b-main.php');
ob_end_flush();
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}
?>
<html>
<head>
<title>Basic Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
<?php
}
?>
<form method="post" name="frmLogin" id="frmLogin">
<table width="400" border="1" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="150">User Id</td>
<td><input name="txtUserId" type="text" id="txtUserId"></td>
</tr>
<tr>
<td width="150">Password</td>
<td><input name="txtPassword" type="password" id="txtPassword"></td>
</tr>
<tr>
<td width="150"> </td>
<td><input type="submit" name="btnLogin" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>