Problem Creating Login Script
Posted: Sun Feb 16, 2003 4:13 am
I run this srcipt but I just get a not validnot valid error, when I have created the username and pass for myself on the database... what is wrong? could you please give me a hand with this.
Thanks alot![/b]
Code: Select all
<html>
<head>
<title>validate.php</title>
</head>
<body>
<?php
$user_name = $_POSTї'user_name'];
$password = $_POSTї'password'];
$db_user = 'mysql_user';
$db_pass = 'mysql_pass';
$user_name = $_POSTї'user_name'];
$password = $_POSTї'password'];
//connect to the DB and select the "dictator" database
$connection = mysql_connect('localhost', $db_user, $db_pass) or die(mysql_error());
mysql_select_db('triple', $connection) or die(mysql_error());
//set up the query
$query = "SELECT * FROM users
WHERE user_name='$user_name' AND password='$password'";
//run the query and get the number of affected rows
$result = mysql_query($query, $connection) or die('error making query');
$affected_rows = mysql_num_rows($result);
//if there's exactly one result, the user is validated. Otherwise, he's invalid
if($affected_rows == 1) {
print 'validated';
}
else {
print 'not valid';
}
//...snip...
if($affected_rows == 1) {
print 'validated';
//add the user to our session variables
$_SESSIONї'username'] = $user_name;
}
else {
print 'not valid';
}
?>
</body>
</html>