I have a survey webpage that if users done it , I will send the data they give (as $_SESSION
from the other pages) and I will change his/her status to 0 (They can't do the survey after that with his/her login info.).
All of these are doing with PDO
. But why the page always redirects to a white blank page?
Here is my code
<?php
session_start();
if (!isset($_SESSION['user']))
{
header("location:index.php");
}
?>
<?php
require_once "condb.php";
?>
<?php
if (isset($_POST['BTN_P2']))
{
$_SESSION['problem'] = $_POST['problem'];
if ($_SESSION['problem'] == "yes"){header("location:survey_3.php");}
else
{
$sql="INSERT INTO data(time,suggest,phone,eat,problem) VALUES(?,?,?,?,?)";
$stm=$cn->prepare($sql);
$stm->bindParam("1",$_SESSION['time']);
$stm->bindParam("2",$_SESSION['suggest']);
$stm->bindParam("3",$_SESSION['phone']);
$stm->bindParam("4",$_SESSION['eat']);
$stm->bindParam("5",$_SESSION['problem']);
try
{
$stm->execute();
try
{
$sqlstatus="INSERT INTO login(status) VALUES(0)";
$stmt=$cn->prepare($sqlstatus);
$stmt->execute();
echo "Finish!";
header('location:finish.php');
}
catch (Exception $error)
{
echo $error->getTraceAsString();
}
}
catch (Exception $e)
{
echo $e->getTraceAsString();
}
}
}
?>
What I am missing?
Edit #1 : Verifying how $_SESSION['user']
comes from.
<?php
if (isset($_POST['BTN_ENTER']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$hashed_password=password_hash($password,PASSWORD_DEFAULT);
try
{
$stmt = $cn->prepare("SELECT * FROM login WHERE username=:username LIMIT 1");
$stmt->execute(array(':username'=>$username));
$result=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0)
{
if(password_verify($password, $result['password']))
{
if ($result['status']==1)
{
$_SESSION['user']=$result['name'];
header('location:survey.php');
}
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}