How to take data from database and store it in session PHP
<p>i want to make TOEFL test. when user want to start the test, first user must input email. So, when user click start, user have an id. I want take id from table 'id' and save it in session. so when i want to take score from 'listening', 'structure' and 'reading' table, i used that id. </p>

<p><strong>but the problem is: when i do the test, listening, reading and structure score will be '0'. but i sure i has answered the questions correctly. Maybe it because id not save in session correctly.</strong> please help meeee</p>

<p>index.php</p>

<pre><code>&lt;form method="POST" action="add_id.php"&gt;
         &lt;input type="text" name="email" placeholder="Email"&gt;
         &lt;input name="btn" type="submit" value="Start"/&gt;
         &lt;/form&gt;
</code></pre>

<p>add_id.php</p>

<pre><code>&lt;?php 
    include "connection.php";
    $email = $_POST['email'];

    $query = "INSERT INTO id(email) VALUES ('$email')";
        if(mysql_query($query)){
         $q = "SELECT * FROM id";
         $ex=mysql_query($q);
         $id = $ex['id'];
         session_start();
         $_SESSION['id'] = $id;

        header("location:test_structure.php");
        }

        else {
        echo mysql_error();
    }
?&gt;
</code></pre>

<p>calculate.php</p>

<pre><code>&lt;?
include "connection.php";
$id   =$_SESSION['id'];

              $query ="SELECT * FROM Reading WHERE Reading.id='$id'";
              $ex=mysql_query($query);
              $data=mysql_fetch_array($ex);
              $right_structure = $data['rightanswer_read'];
              $Reading = $data['score_read'];

              $query ="SELECT * FROM Structure WHERE Structure.id='$id'";
              $ex=mysql_query($query);
              $data=mysql_fetch_array($ex);
              $right_structure = $data['rightanswer_struct'];
              $Structure = $data['score_struct'];

              $q ="SELECT * FROM Listening WHERE Listening.id='$id'";
              $e=mysql_query($q);
              $d=mysql_fetch_array($e);
              $right_listening = $d['rightanswer_list'];
              $Listening = $d['score_list'];

              $final_score = (($Listening + $Structure + $Reading)/3) * 10; 

              $NA = "INSERT INTO final_score VALUES ('$email', '$final_score', '$Listening', '$Structure', '$Reading', '$right_listening', '$right_structure', '$right_reading')";
              if(mysql_query($NA)){
                   header("location:index.php");
              }else {
                    echo mysql_error();
              }

              }
              ?&gt;
</code></pre>

<p>this is <code>id</code> table structure:</p>

<pre><code>CREATE TABLE IF NOT EXISTS `id` (
`id` int(100) NOT NULL,
  `email` varchar(30) NOT NULL
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
</code></pre>