0

I keep getting this error even though I checked my code over dozens of times.

Here I even define SESSION on top as global before using but I keep getting the same error.

<?php if(!isset($_SESSION)) {session_start();}  ?>

Then I use this line of code

<?php error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);?>

It removes the Notice: Undefined index:email error but the email column remains in blank in the database whenever I insert the data.

It says error on this lines of coding.

$s="insert into donation(ddate,units,detail,email) values('" . $d ."' ,'" . $_POST["t3"]
     . "','" . $_POST["t4"] . "','". $_SESSION["email"] ."')";
Greenonline
  • 1,330
  • 8
  • 23
  • 31
tise byte
  • 1
  • 1
  • The problem isn't `$_SESSION`, it's that the index 'email' doesn't exist on `$_SESSION`. – Blue Oct 22 '18 at 06:48
  • 3
    Even if you suppress the error report the error is still there. You're trying to access an index that doesn't exist. I think we need more code than this to help you. Where and how do you set the value for $_SESSION['email'] – Christoffer Oct 22 '18 at 06:55
  • Where you set `email` in the session? Can you show that code. – Talk2Nit Oct 22 '18 at 07:08

2 Answers2

0

try to echo ur session value so u can know u get session value or not...

after session_start();

echo $_SESSION['email'];

lucky
  • 308
  • 2
  • 4
  • 17
0

you have to use session_start(); before applying conditions with $_SESSION. Your code should be :

<?php session_start(); if(!isset($_SESSION)) { //DO SOMETHING HERE } 
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);

 $s="insert into donation(ddate,units,detail,email) values('" . $d ."' ,'" . 
 $_POST["t3"]
 . "','" . $_POST["t4"] . "','". $_SESSION["email"] ."')";
 ?>
livian shrawnia
  • 79
  • 2
  • 11