Log In Script Problems
Posted: Mon Nov 24, 2003 9:47 pm
This is my first piece of code EVER, so I suspect there is much wrong with it. Could someone please help me with why this doesn't work. Essentially, I want it to check for values in the two text fields (username and password), then match the username given with one in the database, the pull out that username and password, and check the password.
Thanks!
--------------------------------------------------------------
<?php
//start session
session_start();
//include files
include("config.inc.php");
//checks for entries
if($_POST['submit']) {
if(!$_POST['username'] | !$_POST['password']) {
die('You didn''t fill in a required field.');
} else {
//mysql query
$query = ("SELECT username, password FROM users WHERE username = "demo")";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_row($result);
}{
//check username and password
if($_POST['password'] = $row['2'])
$_SESSION['auth'] = '1';
echo "Login Successful";
}
else
print ("Username invalid");
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table align="center" border="1" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="username" value=<?php echo ($_POST['password']) or die()?> maxlength="40"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" maxlength="50"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="submit" value="Signin"></td></tr>
</table>
</form>
Thanks!
--------------------------------------------------------------
<?php
//start session
session_start();
//include files
include("config.inc.php");
//checks for entries
if($_POST['submit']) {
if(!$_POST['username'] | !$_POST['password']) {
die('You didn''t fill in a required field.');
} else {
//mysql query
$query = ("SELECT username, password FROM users WHERE username = "demo")";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_row($result);
}{
//check username and password
if($_POST['password'] = $row['2'])
$_SESSION['auth'] = '1';
echo "Login Successful";
}
else
print ("Username invalid");
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table align="center" border="1" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="username" value=<?php echo ($_POST['password']) or die()?> maxlength="40"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" maxlength="50"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="submit" value="Signin"></td></tr>
</table>
</form>