I am trying to create a checklogin.php file. I'm sure people reading this will understand, but to reiterate, I want to make sure the username and password are both in my database before going to the next screen.
Basically my issue is this, when I click Login, I am shown the PHP code of the checklogin.php file instead of directing to the next page or displaying an error at login.
My Login Page:
<html>
<head>
<title>Senior Project Login</title>
</head>
<body>
<p>Please Login: </p>
<form action="checklogin.php" method="POST">
<p>Username: <input type="text" name="username" placeholder="Username" required="required" /> <br/>
<p>Password: <input type="password" name="password" placeholder="Password" required="required" /> <br/><br>
<input type="submit" value="Login"/>
<input type="button" onclick="location.href='SeniorDB_Main.php';" value="Return to Register" />
</form>
</body>
</html>
My checklogin.php file:
<?php
mysql_connect("localhost", "[db]", "[pw]") or die("mysql connection is failure.");
mysql_select_db("[db]") or die("Database does not exists.");
if (isset($_POST['submit'])){
$username=mysql_escape_string($_POST['username']);
$password=mysql_escape_string($_POST['password']);
if (!$_POST['username'] | !$_POST['password'])
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('You did not complete all of the required fields')
window.location.href='htmlogin.html'
</SCRIPT>");
exit();
}
$sql= mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'");
if(mysql_num_rows($sql) > 0)
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Login Succesfully!.')
window.location.href='htmllogin.html'
</SCRIPT>");
exit();
}
else{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Wrong username password combination.Please re-enter.')
window.location.href='htmllogin.html'
</SCRIPT>");
exit();
}
}
else{
}
?>
After doing a lot of research I have a few more questions. I also want to apologize, but my knowledge of this subject was vastly lower than I thought.
1) Do I have to install PHP? All this time I have just been creating files accessing databases using PHP, never installed anything.
2) How do I know how I am accessing this database? Currently, it is on a server provided by my professor and we just create the database and put the files in it. Do I have to install something into that as well?
3) I went to PHP code is not being executed, instead code shows on the page to see if I can work out a solution from there and everything was way over my head, I didn't understand what happened.
If anyone can explain (in newbie talk) what is happening that would be awesome.