0

What I want is the login to get the data from the database, and display the welcome page. \im not sure why it is not working, I had PHP 8 and I did my code I always get a blank page, be it retrieving data from a database or adding data. all I get is a blank page with no action. This is my HTML code:

**<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Movie Site</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="login">
<h1>MY MOVIE SITE</h1>
<h1>Login</h1>
<form action="insert.php" method="post">
<input type="text" name="u" placeholder="username" required="required" />
<input type="password" name="p" placeholder="password" required="required" />
<button type="submit" class="btn btn-primary btn-block btn-large">Let me in.</button>
</form>
</div>
</body>
</html>**

Then my PHP is:

**<?php
    
$username = $_POST['username'];
$password = $_POST['password'];
    
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
    
mysql_connect("localhost", "root", "");
mysql_select_db("login");
    
$result = mysql_query("select * from user where username = '$username' and password = '$password'")
or die ("failed to query database".mysql_error());
$row = mysql_fetch_array($result);
if ($row['username'] == $username && $row['password'] == $password){
echo "login success!! WELCOME ".$row[username];
}
else{
echo 'Failed to log in';
}
    
?>**

Thanks in advance. I have tried and checked where I am wrong and googled, I don't seem to understand what I am missing out on. PHP version I'm using is 7.2.34 I moved the version lower from 8 since I thought it could be version errors and wrong syntax with the new version. But doesn't seem to be the case.

KaurCodes
  • 7
  • 3
  • 1
    Try enabling error logging `error_reporting(-1); ini_set('display_errors', 'On');` and see what is error is coming. – Avinash Dalvi Dec 08 '20 at 06:20
  • It should be noted that the MySQL extension you are trying to use has been deprecated since PHP 5.5.0 and removed in PHP 7. Try using the mysqli or PDO to connect to your database. – Dawson Irvine Dec 08 '20 at 06:24
  • 2
    Take a look att the `mysqli` extension instead (notice the "i" at the end). Furthermore, you are refering to `username` and `password` in the `$_POST`, but in your form you gave them the names `u` and `p` – Gowire Dec 08 '20 at 06:25
  • 1
    Out of MySQLi and PDO, I'd strongly recommend PDO, especially for newbies – Phil Dec 08 '20 at 06:38

0 Answers0