I am trying to create a login to database, using PHPMyAdmin with MAMP. I have made a simple login form in index.html and placed my php code in connect.php to open home.php once the correct username and password are put in. But when I input username and password (or even when I input random text) I am taken to localhost:8888/connect.php with no error message, just a blank page. Any ideas?
This is the index.html code
<head>
<body>
<font>
<center><h1>Login</h1></center>
</font>
<form action="connect.php" method="POST">
Username:<input type="text" name="username">
Password:<input type="password" name="pass"><br>
<input type="submit" value="login" name="submit">
</form>
</body>
</head>
And this is in connect.php
<?php
require ('msql_connect.php');
if (isset($_POST['submit'])){
$username=mysql_escape_string($_POST['username']);
$password=mysql_escape_string($_POST['pass']);
}
$inputuser = $_POST['user'];
$inputpass = $_POST['pass'];
$user = "root";
$database = "test";
@mysql_select_db($database) or ("Database not found");
$query = "SELECT * FROM 'login' WHERE 'user' = '$username' AND 'password' = '$password'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if(!$result){
echo "Sorry, bad login";
die("Username or password is invalid");
//Might be better to redirect back to the login page with a freindly message
} else {
$valid_user = mysql_fetch_array($result);
mysql_close();
header('Location: home.php');
}
?>
UPDATE: There is no mysql_connect.php, I've changed the all mysql_ to mysqli_, and commented out the require() and it brings me to an error message of wrong username and password, but they should be working.
Now looks like this
<?php
// require ('connect.php');
if (isset($_POST['submit'])){
$username=mysqli_escape_string($_POST['username']);
$password=mysqli_escape_string($_POST['pass']);
}
$inputuser = $_POST['user'];
$inputpass = $_POST['pass'];
$user = "root";
$password = "";
$database = "fuf_db";
$connect = mysqli_connect("localhost",$user,$password);
@mysqli_select_db($database) or ("Database not found");
$query = "SELECT * FROM 'SuperAdminUsers' WHERE 'user' = '$username' AND 'password' = '$password'";
$result = mysqli_query($query);
if(!$result){
echo "Sorry, bad login";
die("Username or password is invalid");
} else {
// $row = mysqli_fetch_array($result);
$valid_user = mysqli_fetch_array($result);
mysqli_close();
header('Location: home.php');
}
?>
These are the errors I'm getting :-
Warning: mysqli_escape_string() expects exactly 2 parameters, 1 given in .../connect.php on line 5
Warning: mysqli_escape_string() expects exactly 2 parameters, 1 given in .../connect.php on line 6
Notice: Undefined index: user in .../connect.php on line 9
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in .../connect.php on line 15
Warning: mysqli_query() expects at least 2 parameters, 1 given in .../connect.php on line 20 Sorry, bad loginUsername or password is invalid