Padgoi Posted June 21, 2007 Share Posted June 21, 2007 I have this small script that allows logged in users to write messages to a bulletin and the bulletins are posted. However, there's something wrong with it. If I log in as one user and post something, then log in as another user, it always reverts back to the first user. It's something with the SESSION I know I did wrong. Furthermore, I want to limit the bulletin to only show the last 5 entries. Any help with this? <?php if(isset($_SESSION["user"]) and isset($_SESSION["userid"])) { if(isset($_POST['go'])){ $body=$_POST['body']; $user=$_SESSION['user']; $date=time(); $sql="insert into prof_bull (body, user, post) values('$body', '$user', $date)"; mysql_query($sql); // echo $sql; } $sql="select * from prof_bull where sid='$id'"; $resul2t=mysql_query($sql); $com=mysql_fetch_assoc($resul2t); $title=$com['title']; echo "<h1>$title</h1><hr>"; $sql="select * from prof_bull where sid='$id'"; $result=mysql_query($sql); //echo $sql; ?> <table border=1> <?php while($info=mysql_fetch_assoc($result)){ $body=$info['body']; $user=$info['user']; $date=date("F j, Y, g:i a",$info['post']); echo "<tr><td> $body <br /> <i>posted by $user on $date</i> </td></tr>"; } echo "</table>"; ?> <?php echo "<form action=\"?id=$id\" method=\"POST\">"; ?> Comment<br /> <textarea name="body"></textarea><br /> <input type="Submit" name="go" value="Submit" /> </form> <?PHP } else { } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56624-need-help-with-php-code/ Share on other sites More sharing options...
pocobueno1388 Posted June 21, 2007 Share Posted June 21, 2007 To show the last five entires, just change your query to this: <?php $sql="select * from prof_bull where sid='$id' LIMIT 5 ORDER BY bulletinID"; ?> I am assuming you have an unique auto-increment column, that is what you should replace the work "bulletinID" with. Quote Link to comment https://forums.phpfreaks.com/topic/56624-need-help-with-php-code/#findComment-279609 Share on other sites More sharing options...
pocobueno1388 Posted June 21, 2007 Share Posted June 21, 2007 Maybe for the session problem, you are not correctly destroying them on your logout script. Are you using session_destroy()? That is a shot in the dark at the session problems, but that could be it =] Maybe you could post the script to where you register the session(s) at, and also the script that destroys the sessions. It would be much easier to figure out the problem if we had the code. Quote Link to comment https://forums.phpfreaks.com/topic/56624-need-help-with-php-code/#findComment-279611 Share on other sites More sharing options...
php2MySQL Posted June 21, 2007 Share Posted June 21, 2007 $sql="select * from prof_bull where sid='$id' ORDER BY id DESC LIMIT 5"; Quote Link to comment https://forums.phpfreaks.com/topic/56624-need-help-with-php-code/#findComment-279612 Share on other sites More sharing options...
Padgoi Posted June 21, 2007 Author Share Posted June 21, 2007 the problem with the session is in this bit because without this bit, it works fine. With this bit, that's when the session problem shows up. Quote Link to comment https://forums.phpfreaks.com/topic/56624-need-help-with-php-code/#findComment-279639 Share on other sites More sharing options...
teng84 Posted June 21, 2007 Share Posted June 21, 2007 show me or check you initialization of that session also show how you distroy the session ASTIG!!! Quote Link to comment https://forums.phpfreaks.com/topic/56624-need-help-with-php-code/#findComment-279650 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.