Jump to content

Recommended Posts

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
{
}
?>

Link to comment
https://forums.phpfreaks.com/topic/56624-need-help-with-php-code/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.