I am relatively new to coding things in php and am looking for help with what I am doing wrong. I've been looking through this site for the last few hours and can't find anything that specifically answers my question. So any help would be greatly appreciated.
I am trying to make a really simple login to a page using only a password. It seems though I did something wrong. I made everything live on the ftp server and went to login to my members page.
UPDATED: Below is the final code that worked out for me.
Here is the code I put at the top of "members.php":
<?php
error_reporting(E_ALL);
session_start();
if(!isset($_SESSION['loggedin'])){
header("location:login2.php");
}
?>
That sends me to "login.php" which I can get to. Below is what my form code looks like on this page:
<form name="form1" method="post" action="checklogin.php">
<label for="password">This Area Requires a Password:</label>
<input name="password" type="text" id="password">
<div id="lower">
<input type="submit" name="Submit" value="Login">
</div>
</form>
Once someone enters the password (there is only one password), the submit/login button is supposed to take them to "checklogin.php" which then redirects them to "members.php". Unfortunately, that is not happening. It simply clears what I typed in the password box and stays on the same page (login.php) and I don't get any error messages.
Below is the code I have on "checklogin.php":
<?php
error_reporting(E_ALL);
session_start();
$host="";
$username="";
$password="";
$db_name="";
$tbl_name="";
mysql_connect($host, $username, $password) or die("cannot connect");
mysql_select_db($db_name) or die("cannot select DB");
$mypassword=$_POST['password'];
$mypassword = stripslashes($mypassword);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$_SESSION["loggedin"] = "true";
header("location:members2.php");
}
else {
echo "Wrong Password";
}
?>
I took out the database login info for my sites security, but I did set up a table within the database that looks like this:
So I'm not quite sure what I am missing, but that probably is because I'm rather new to it. Any help would be greatly appreciated and of course if you have any questions, please feel free to ask. Also, if anyone might suggest a way to encrypt the password, that would be great as well. Thank you.


