pass the value of get_insert_id
<p>Can you please help me here.
I am trying to save the last id inserted, but it keeps on saving 0, which I don't understand why. Sorry noob here :(
Here are my codes</p>

<p>the index</p>

<pre><code>&lt;form action="save_member.php" method="POST"&gt;
            Enter your username: &lt;input type="text" name="member"/&gt;
            &lt;input type="submit" value="Submit"/&gt;
        &lt;/form&gt;
</code></pre>

<p>the save_member</p>

<pre><code>include 'connect.php';
session_start();
$_SESSION['member_id'] = $_POST[member];
$sql = mysql_query("insert into users (idusers, member) values ('', '$_POST[member]')");
$_SESSION['last_id'] = mysql_insert_id();
header("Location: chat.php");
</code></pre>

<p>the chat</p>

<pre><code>    &lt;?php
    session_start();
    echo "hello" . " " . $_SESSION['member_id'];
    echo "&lt;br/&gt;";
    ?&gt;
    &lt;?php
    include 'connect.php';
    $q = mysql_query("select * from messages order by time_sent desc");
    while ($w = mysql_fetch_array($q)) {
        ?&gt;
        &lt;div id="show_messages" style=""&gt;
            &lt;span id="wrap_messages" style=""&gt;
                &lt;span id="message" style=""&gt;&lt;?php echo $w['message']; ?&gt; &lt;/span&gt; :
                &lt;span id="member_id" style=""&gt;&lt;?php echo $w['member_id']; ?&gt;&lt;/span&gt;
            &lt;/span&gt;
        &lt;/div&gt;
    &lt;?php } ?&gt;
    &lt;br/&gt;
    &lt;div style="margin-right: 450px !important; width: 300px; float: right;"&gt;
        &lt;form action="sent_chat_message.php" method="POST"&gt;
            &lt;input type="hidden" name="member_id"/&gt;
            &lt;input type="text" name="chat"/&gt;
            &lt;input type="submit" value="Submit"/&gt;
        &lt;/form&gt;
    &lt;/div&gt;
</code></pre>

<p>and the sent_chat_message</p>

<pre><code>include 'connect.php';
session_start();
$_SESSION['last_id'] = $last_id;
$r = mysql_query("insert into messages (idmessages, message, member_id) values ('', '$_POST[chat]', '.$last_id.')");
header("Location: chat.php")
</code></pre>
