Page not moving to header location

I have the following code and using echo’s I have chased the information down the page and still when it gets to used header location in a successful login it doesnt go there.

<?php
include "config.php";
error_reporting(E_ALL);
ini_set('display_errors','On');

//Sanitize the POST values
$username = $_POST["username"];
$password = $_POST["password"];

//Input Validations
if($username == '') {
$errmsg_arr[] = 'Username missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password missing';
$errflag = true;
}

//Create query
//var_dump("SELECT * FROM moduleUsers WHERE username=".$username." AND password=".$password."");
$qry="SELECT * FROM moduleUsers WHERE username=".$username." AND password=".$password.";
$result=mysqli_query($link,$qry) or die(mysqli_error());

//Check whether the query was successful or not
if($result) {
if(mysqli_num_rows($result) > 0) {
//Login Successful
session_regenerate_id();
$member = mysqli_fetch_assoc($result);

$_SESSION['SESS_MEMBER_ID_2'] = $member['module_ID'];
$_SESSION['SESS_FIRST_NAME_2'] = $member['first_Name'];
$_SESSION['SESS_LAST_NAME_2'] = $member['last_Name'];

session_write_close();

header("location: /user_Admin/modules.php");

exit();
}else {
//Login failed
$errmsg_arr[] = 'your log in details are incorrect';
$errflag = true;
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}
}
}else {
die("Query failed");
}
?>

When I use var_dump to check on things as I have commented out above, I then get this error.

mysqli_error() expects exactly 1 parameter, 0 given in /home/ukequine/public_html/login_exec.php on line 39

Which is

$result=mysqli_query($link,$qry) or die(mysqli_error());

But like I said when I use var_dump it out puts the details fine
“SELECT * FROM moduleUsers WHERE username=x AND password=y”

$result=mysqli_query($link,$qry) or die(mysqli_error($link));

1 Like

AAAAAAAAAAAAAHHHHHHHHHHHHH!!!

Cheers Felgall, drives me crazy those little ones.

It has moved on, and I’m getting an error like this now.

Warning:  session_regenerate_id(): Cannot regenerate session id - headers already sent in

In relation to -

if(mysqli_num_rows($result) > 0) {
//Login Successful
session_regenerate_id();
$member = mysqli_fetch_assoc($result);

And Warning: Cannot modify header information - headers already sent by

header("location: /user_Admin/modules.php");

This is where I got to before, and it doesnt seem to want to move on, but its not an error, but just returns to the login page.

I have made sure of no spaces top and bottom, even selecting all the code, deleting it, pasting it into notepad, then copy and pasting back and still doesnt like it.

Thanks felgall though, always appreciate your help, and I’m always taking it on board

There’s some discussion around that suggests your error_reporting setting might be causing the “headers already sent” message. I couldn’t find a specific post anywhere, just some rumbling.

Hi guys,

I managed to sort out the problem by adding

session_start();

Above session_regenerate_id(); which allowed the page to move on successfully.

Thanks again

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.