Here is the code that I’m working on:
login.php:
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("koro",$con);
$result= "SELECT * FROM users WHERE
UNAME='".mysql_real_escape_string($_POST['Uneym'])."'";
echo $result;
$num=mysql_num_rows($result);
echo $num;
for($i=1;$i<=$num; $i++){
while($row=mysql_fetch_array($result))
{
$user=$row['UNAME'];
$pass=$row['PW'];
}
}
if($username == $user && $password ==$pass)
{
echo "<script>alert('Login Successful!')</script>";
}
else if($password!= $pass ||$username != $user )
{
echo("Please Enter Correct Username and Password ...");
?>
loginform.php:
<html>
<form action="login.php" method="post">
Username:<input type="text" name="Uneym" value="" /><br/>
Password:<input type="password" name="Pass" value="" /><br/>
<br/>
<input type="submit" name="Submit" value="" />
</form>
</head>
<body>
</body>
</html>
-Is there a simpler code for a beginner like me?:)
Your code isn’t too complex – it can’t be made much simpler at all if it is to do the job.
But, you shouldn’t be storing passwords in your database unencrypted like that. Take a look at this article on hashing passwords in mysql.