0

So, when I run this code on xampp, it works and I can see the variables, without the header.

<html>
<head>
</head>
<body>
<?php
$user="";
$server="";
$db="";
$pass="";
$con=mysqli_connect($server,$user,$pass,$db);

$id=$_POST['loginid'];
$password=md5($_POST['password']);

$result=mysqli_query($con,"SELECT * FROM passwords WHERE userid='$id' AND password='$password'");
session_start();
if($row=mysqli_fetch_array($result)){
require('../connect/registerdb.php');
$rresult=mysqli_query($rcon,"SELECT * FROM registration WHERE userid='$id'");
while($rrow=mysqli_fetch_array($rresult)){

$_SESSION['name']=$rrow['name'];
$_SESSION['dob']=$rrow['dob'];
$_SESSION['userid']=$rrow['userid'];
$_SESSION['sex']=$rrow['sex'];
$_SESSION['family']=$rrow['family'];
$_SESSION['describe']=$rrow['describe'];
$_SESSION['pic']=$rrow['pic'];
$_SESSION['visibility']=$rrow['visibility'];
$_SESSION['registeredon']=$rrow['registeredon'];
$_SESSION['lastlogin']=$rrow['lastlogin'];
require('../connect/emaildb.php');
$eresult=mysqli_query($econ,"SELECT email FROM emaillist WHERE userid='$id'");
while($erow=mysqli_fetch_array($eresult)){
$_SESSION['email']=$erow['email'];
}
}
header('Location:../mainpage.php');
}
?>
</body>
</html>

When I add the header, I get:

Notice: Undefined index: loginid in C:\xampp\htdocs\website\session\session.php on line 12

Notice: Undefined index: password in C:\xampp\htdocs\website\session\session.php on line 13

Why does it work without the header but not with the header?

2
Contributors
4
Replies
25
Views
3 Years
Discussion Span
Last Post by DJBirdi
0

session_start() needs to be before any variable declarations/html. Try putting

<?php
    session_start();
?>

at the top of the page, and delete your line 16.

0

No, sorry. It didn't fix it.

Edited by david.roun.7: Typo. Shouldn't have said "I"

0

Ahh ok, this seems like one of those cases where with all the "*AMP" localhost servers, it could just be a matter of setting specific permissions and allowing certain mods to be run on your localhost

Don't forget to mark this thread solved if you got what you need :)

Edited by DJBirdi

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.