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.
<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>
I finally got 2 validated things =) thanks everyone, now can you sudgest a tutorial to show how to use sessions and how to now move onto a new page, the homepage.
You are going to have to rewrite the whole script. You need to replace $_POST with $HTTP_POST_VARS and are going to have to do your sessions differently too. You need to use the session_register() function and cannot use $_SESSION.
I downloaded a ready configured pack because I could not work out how to compile it with mySQL seperatley.... but now I am just getting confused because it will work on my localhost but not the website