I know my code is shabby, but I don't think it's really that at fault for it here?
Managed to work out how to redirect users to different pages depending on their level as given through a login/register form, and it worked okay locally on my computer. No errors or bugs detected, and by manual testing it seemed okay.
I then uploaded the entire login/register program on a free hosting site (000webhost) with essentially identical code, yet the outcomes are very different for my validation process: post-login screen, locally hosted; post-login screen, on 000webhost.
Specifically, the errors are:
Warning: Undefined array key "level" in /storage/ssd1/382/21909382/public_html/validation.php on line 15
Warning: Undefined array key "admin" in /storage/ssd1/382/21909382/public_html/validation.php on line 27
Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd1/382/21909382/public_html/validation.php:15) in /storage/ssd1/382/21909382/public_html/validation.php on line 28
The lines in question are:
Line 15: $level = $_POST['level'];
Line 27: $_SESSION["admin"];
Line 28: header('location:Admin Page.php');
Here is the complete file where the errors appear:
<?php
session_start();
$con = mysqli_connect('localhost','id21909382_biyo','!Biyo123');
mysqli_select_db($con, 'id21909382_access_levels');
if(isset($_POST['submit'])){
$name = $_POST['user'];
$pass = $_POST['password'];
$level = $_POST['level'];
echo $value ?? '';
$select = " select * from usertable where name = '$name' && password = '$pass'";
$result = mysqli_query($con, $select);
if (mysqli_num_rows($result) > 0){
$row = mysqli_fetch_array($result);
if($row['level'] == 'admin'){
$_SESSION["admin"];
header('location:Admin Page.php');
}elseif($row['level'] == 'user'){
$_SESSION["user"];
header('location:User Page.php');
}
}else{
header('location:index.php');
}
}
?>
It's already strange enough that the two have vastly different outcomes despite being the same (the only thing that varies between them is $con = mysqli_connect('localhost','id21909382_biyo','!Biyo123');) due to 000webhost having different credentials for phpmyadmin. Even worse, all of the error-lines have similar ones that are error-free: line 27's $_SESSION["admin"]; is similar to $_SESSION["user"]; just a few lines after, for example. Much of the code is also copy-pasted from the registration file within my program, yet no problems there.
What exactly did I do wrong that is causing this discrepancy?
The problem eventually resolved itself. Randomly tried logging in again and it spontaneously worked.