Live Helper Chat support forum.. Forum is locked. New place for questions - Github Discussions
You are not logged in.
Pages: 1
I have been trying to get validation messages from my login.php to display on the page with the form, where am I going wrong? I did try JavaScript at one point to display the information with no luck, it keeps displaying as seen in the image below.
I know it could be added to the same page for the result I want but I'm trying to do it as a clean page, with no jQuery, some vanilla JavaScript at very most. The aim is to have the validation messages above the form, at first I was thinking spans but I'm not sure where to look for tutorials on how to output results from another file while staying on the same page.
<table border ='0'>
<form action="login.php" method="POST">
<tr><td>Username:</td> <td><input type="text" name="username" required></td></tr>
<tr><td>Password:</td> <td><input type="password" name="password" required></td><tr>
<tr><td><input button id="myBtn" type="submit" value="Log in"><td></tr>
<tr><td><a href='register.php'>Register</a></td></tr>
</table>
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$errors = array();
if ($username&&$password)
{
$connect = mysql_connect("localhost","root","") or die ("Could not connect");
mysql_select_db ("login") or die ("Could not find database");
$query = mysql_query("SELECT * FROM users WHERE username ='$username'");
$numrows = mysql_num_rows($query);
if ($numrows !=0)
{
while ($row =mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
if ($username==$dbusername&&$password==$dbpassword)
{
echo header( 'Location: member.php' ) ;
$_SESSION['username']=$dbusername;
}
else
echo"
<script type=\"text/javascript\">
window.onload = function latestNews(){
var newPara = document.createElement('p');
var add_news = document.createTextNode('Incorrect password');
newPara.appendChild(add_news);
var getSecond = document.getElementById('footer');
document.body.insertBefore(newPara, getSecond);
};
</script>
";
}
else
die("That user dosen't exist");
}
else
die("Please enter a username and a password");
?>
Offline
Forms support only html.
P.s you php code has SQL vulnerability. You have to escape everything you pass to your SQL statement.
Offline
Pages: 1