Hi,
I've been learning PHP over the weekend and have covered quite a bit with a very good tutorial I've been following I basically need to create a members area for a site. Now I know I could do it with cookies but obviously that isn't very secure so I wanted to do it with mySQL (the tutorial covered it as well) but am a bit confused on how to do it. So far, I have created a MyISAM table with the fields of 'user' and 'pword' and have the following script:
Now, the script works perfectly but I'm not sure what I have to do when I add more users. I understand that this is probably not the best way of doing things but I only started on saturday night So could anyone suggest a fix or a better way of doing things?
Thanks
Ben
I've been learning PHP over the weekend and have covered quite a bit with a very good tutorial I've been following I basically need to create a members area for a site. Now I know I could do it with cookies but obviously that isn't very secure so I wanted to do it with mySQL (the tutorial covered it as well) but am a bit confused on how to do it. So far, I have created a MyISAM table with the fields of 'user' and 'pword' and have the following script:
Code:
<?php
// Set Database Connection Parameters:
$host = "localhost";
$user = "********";
$pword = "********";
$dbase = "membersarea";
// Connect to Database:
$connect = mysql_connect($host, $user, $pword) or die('Could not connecto to database!');
// Select Database:
mysql_select_db($dbase) or die('Could not select database');
// Set User Input Variables:
$username = $_POST['username'];
$password = $_POST['password'];
// Define Query:
$query = "SELECT * FROM user_info";
// Execute Query:
$result = mysql_query($query) or die("Error in query: $query" .mysql_error());
$row = mysql_fetch_row($result);
// If Username and Password are correct, include the members page:
if (($row[1] == $username) && ($row[2] == $password)) {
echo "Username and password accepted";
echo "<br /><br />";
include('membersarea.php');
}
// If the Username is correct but the password wrong, display the wrong username page:
elseif (($row[1] == $username) && ($row[2] != $password)) {
echo "Username found but the password is incorrect";
}
else {
echo "Username not found";
}
// Free Result Set Memory:
mysql_free_result($result);
// Close Connection:
mysql_close($connect);
?>
Now, the script works perfectly but I'm not sure what I have to do when I add more users. I understand that this is probably not the best way of doing things but I only started on saturday night So could anyone suggest a fix or a better way of doing things?
Thanks
Ben