Hello again!
The few tutorials I saw for user registrations / logins were extremely helpful. But again I’m stuck. I’m working on my localhost server to create a basic table database login.
For some reason I can’t login with a created user unless I put in the encrypted password and not the actual one. I know I must have encrypted something wrong.
Below is my code for the register (it works, creates a user / password etc) I got the code from PHPAcademy up on YouTube, it’s been a great help, but this issue has my stumped.
Thanks in advance!
<?php
echo “<h1>Please Register</h1>”;
$submit = $_POST[‘submit’];
//form data
$fullname = strip_tags($_POST[‘fullname’]);
$username = strip_tags($_POST[‘username’]);
$password = strip_tags($_POST[‘password’]);
$repeatpassword = strip_tags($_POST[‘repeatpassword’]);
$date = date(“Y-m-d”);
if ($submit)
{
//check for existing using
if($fullname&&$username&&$password&&$repeatpassword)
{
if ($password==$repeatpassword)
{
//check character length
if (strlen($username)>25||strlen($fullname)>25)
{
echo "Username / Full Name is too long!";
}
else
{
//check password
if(strlen($password)>25||strlen($password)<5)
{
echo "Password must between 5 and 25 characters!";
}
else
{
//register user
//encryption
$password = md5($password);
//open database
$connect = mysql_connect("localhost","root","root");
mysql_select_db("phplogin");//selectdatabase
$queryreg = mysql_query("
INSERT INTO users VALUES ('','$fullname','$username','$password','$date')
");
die ('"You have been registered! <a href="index.php">Click Here</a> to continue"');
}
}
}
else
echo "Your passwords do not match!";
}
else
echo "Please fill in <b>all</b> fields!";
}
?>
<!–do not touch below this line–>
<html>
<p>
<form action=‘register.php’ method=“POST”>
<table>
<tr>
<td>
Your fullname:
</td>
<td>
<input type=‘text’ name=‘fullname’ value=“<?php echo $fullname ?>”>
</td>
</tr>
<tr>
<td>
Choose a username:
</td>
<td>
<input type=‘text’ name=‘username’ value=“<?php echo $username ?>”>
</td>
</tr>
<tr>
<td>
Your Password:
</td>
<td>
<input type=‘password’ name=‘password’>
</td>
</tr>
<tr>
<td>
Repeat your password:
</td>
<td>
<input type=‘password’ name=‘repeatpassword’>
</td>
</tr>
</table>
<p>
<input type=‘submit’ name=‘submit’ value=“Register”>
</form>
</html>
This is the login form
<?php
session_start();
$username = $_POST[‘username’];
$password = $_POST[‘password’];
if($username&&$password)
{
$connect = mysql_connect(“localhost”,“root”,“root”) or die(“Couldn’t Connect!”);
mysql_select_db(“phplogin”) or die(“Couldn’t find db”);
$query = mysql_query("SELECT * FROM users WHERE username ='$username'");
$numrows = mysql_num_rows($query);
if ($numrows!=0)
{
// code to login
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
// check to see if they match
if ($username==$dbusername&&md5($password)==$dbpassword)
{
echo "your in! <a href='member.php'>Clck here</a> to enter member page";
$_SESSION['username']=$dbusername;
}
else
echo "Incorrect password!";
}
else
die ("That user doesn't exist");
}
else
die(“Please enter username and password!”);
?>