I am trying to create a very basic log in script for a website only used by a select group of people.
I have created the HTML form and mysql database with the relevant log ins etc, however when I try the site on my server, once the form is submitted and it redirects me to my login.php, it throws up a 500 Intrernal Server Error.
Here are the php files: login.php
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
$myusername = mysqli_real_escape_string($db,$_POST['username']);
$mypassword = mysqli_real_escape_string($db,$_POST['password']);
$sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$mypassword'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count == 1) {
session_register("myusername");
$_SESSION['login_user'] = $myusername;
header("location: welcome.php");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>
config.php
<?php
define('DB_SERVER', '*****');
define('DB_USERNAME', '***');
define('DB_PASSWORD', '***');
define('DB_DATABASE', '****');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
(Obviously I have removed the database information for this purpose). Any advice would be greatly appreciated, I have spent hours trawling the internet, trying different scripts or solutions and watching tutorials.
Please be gentle, I'm new to all this. Thanks!