<!DOCTYPE html>
<html></html>
<body>
<?php
$con=mysqli_connect('localhost','id169218_venki','**********','id169218_mydb');
session_start();
if(isset($_POST['loginbtn'])){
$email=$_POST['email'];
$password=$_POST['pwd'];
$result=mysqli_query($con,'select * from myguests where email="'.$email.'" and password="'.$password.'"');
if(mysqli_num_rows($result)==1)
{
$_SESSION['email']= $email;
header("Location:welcome.php");
}
else
echo"INVALID ACCOUNT";
}
?>
</body>
</html>
AND THIS IS MY welcome.php
<html>
<body>
<?php
function error_found(){
header("Location: login.php");
}
set_error_handler('error_found');
?>
<?php
session_start();
echo"welcome " .$_SESSION['email'];
?>
<br><a href="logout.php">logout</a>
</body>
</html>
sry this is not working
should i use any other supporting code or header files to use this command
1 Like
Are you sure it doesnt echo INVALID?
The bug:
Correct
else {
echo"INVALID ACCOUNT";
}
2 Likes
To display PHP errors please go to 000webhost cPanel > Settings > General > Show errors > On> Off > On
1 Like
yes i done
.i on that
1 Like
If header isn’t working it is because the php code is under the <!DOCTYPE html>
. To resolve this, but the php code on the top of <!DOCTYPE html>
Example :
<?php // the code is on the start of the file
$con=mysqli_connect('localhost','id169218_venki','**********','id169218_mydb');
session_start();
if(isset($_POST['loginbtn'])){
$email=$_POST['email'];
$password=$_POST['pwd'];
$result=mysqli_query($con,'select * from myguests where email="'.$email.'" and password="'.$password.'"');
// mysqli is a bit outdated to be honest. consider using PDO
if(mysqli_num_rows($result)==1)
{
$_SESSION['email']= $email;
header("Location:welcome.php");
}
else
die("INVALID ACCOUNT"); // Use the command die for dyin... uhh i mean display something and interrupt the code.
}
?>
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Here you go !
1 Like
I done that but it is not working
<?php
session_start();
$_SESSION['name']='Guru';
echo $_SESSION['name'];
header("Location:logout.php");
?>
this page contain php element only but this will not redirect me to the logout page
Can you add a space between Location: and logout.php
Whoops, forgot a semicolon in die([...]
!