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
the index
<form action="save_member.php" method="POST">
Enter your username: <input type="text" name="member"/>
<input type="submit" value="Submit"/>
</form>
the save_member
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");
the chat
<?php
session_start();
echo "hello" . " " . $_SESSION['member_id'];
echo "<br/>";
?>
<?php
include 'connect.php';
$q = mysql_query("select * from messages order by time_sent desc");
while ($w = mysql_fetch_array($q)) {
?>
<div id="show_messages" style="">
<span id="wrap_messages" style="">
<span id="message" style=""><?php echo $w['message']; ?> </span> :
<span id="member_id" style=""><?php echo $w['member_id']; ?></span>
</span>
</div>
<?php } ?>
<br/>
<div style="margin-right: 450px !important; width: 300px; float: right;">
<form action="sent_chat_message.php" method="POST">
<input type="hidden" name="member_id"/>
<input type="text" name="chat"/>
<input type="submit" value="Submit"/>
</form>
</div>
and the sent_chat_message
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")