I am new to the world of PHP, i wanted to start with something simple and build my understanding from there!
I have simple looking codes, but it is really being a little pest to me, and giving me errors, right after I fix another. Can anyone who has travel in my tracks before
show me how these codes should actually look like, please.😕
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$connect = mysql_connect("localhost","root","") or die("Couldn't connect!");
mysql_select_db("phpuserlogin") or die("Couldn't find db");
$query = mysql_query("SELECT * FROM users WHERE username= '$username'");
$numrows = mysql_num_rows($query);
if (numbers!=0)
{
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 "You're in! <a href='member.php'>Click</a> here to enter the member page";
$_SESSION['username']=$username;
}
else
echo "Incorrect password!";
}
else
die("That user doesn't exist!");
}
?>
<?php
echo "<h1>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)
{
echo "Please fill in <b>all </b> fields!";
}
//check for existance
if ($fullname&&$username&&$password&&$repeatpassword)
{
if ($password==$repeatpassword)
{
// check char length of username and fullname
if (strlen($username)>25||strlen($fullname)>25)
{
echo "Length of username or fullname is too long!";
}
else
{
//check password length
if (strlen($password)>25||strlen($password)<6)
{
echo "Password must between 6 and 25 characters";
}
else
{
//register the user!
//encrypt password
$password = md5($password);
$repeatpassword = md5($repeatpassword);
echo "Success!!";
}
}
}
else
echo "Your passwords do not match!";
?>