Jump to content

[SOLVED] Basic forum code question


graham23s

Recommended Posts

Hey Guys,

 

i have coded a little forum very basic more of a message board type thing, theres 1 thing i have been unable to do, when a user posts a message/rely i while loop them out, i was wanting to put an "EDIT" button next to the users reply so they can click and edit it quickly,

 

but i only want the user to see the "EDIT" button next to the post that belongs to them (obviously lol) so only the user who made the post can edit it.

 

heres the code:

 

<?php
     // get the id...////////////////////////////////////////////////////////////////////
     $topic_post_id = $_GET['id'];
     
     // Update the view column...////////////////////////////////////////////////////////
     $sql_update = "UPDATE `forum_topics` SET `views`=views+1 WHERE `id`='$topic_post_id'"; 
     $result_update = mysql_query($sql_update);
     
     // get the topic message.../////////////////////////////////////////////////////////
     $query = "SELECT * FROM `forum_topics` WHERE `id`='$topic_post_id'";
     $result = mysql_query($query) or die (mysql_error());
     $rows = mysql_fetch_array($result) or die (mysql_error());
     
     $topic_name = $rows['topic_name'];
     $topic_body = $rows['topic_body'];
     $user_id = $rows['user_id'];
     $topic_added = $rows['date_added'];
     
     // who posted the topic?.../////////////////////////////////////////////////////////
     $query2 = "SELECT * FROM `membership` WHERE `id`='$user_id'";
     $result2 = mysql_query($query2) or die (mysql_error());
     $row = mysql_fetch_array($result2) or die (mysql_error());
     
     $posting_id = $row['id'];
     $posting_user = $row['username'];
     
     ## table ###########################################################################
     echo '<br /><br /><br />
           <table width="500" border="1" bordercolor="#000000" cellspacing="0" celpadding="0"/>
           <tr>
           <td colspan="2" bgcolor="#004E98"><font color="#ffffff"><b>Reading Post (</font><font color="red">'.$topic_name.'</font><font color="#ffffff">) By <a href="user_details.php?id='.$posting_id.'"/><font color="#ffffff">'.$posting_user.'</b></font></a></td>
           </tr>
           <tr>
           <td width="10" align="center" bgcolor="#004E98"><img src="images/forum_icon.gif"/></td><td width="490" align="left">'.$topic_body.'</td>
           </tr>
           <td colspan="2" bgcolor="#004E98" align="center"><font color="#ffffff"><b>Posted On: '.$topic_added.'</b></font></td>
           </table><br />';
     ## table ###########################################################################
                
     ## get the comments and display them ###############################################
     $query5 = "SELECT * FROM `forum_posts` WHERE `topic_id`='$topic_post_id' ORDER BY `date_added` ASC"; 
     $result5 = mysql_query($query5); 

     if(mysql_num_rows($result5)) {
     
     while ($row_display = mysql_fetch_array($result5)) {
     
     $post_id = $row_display['id'];
     $user_id = $row_display['user_id'];
     $post_body = $row_display['post_body'];
     $post_date = $row_display['date_added'];
     
     // get the usernames and links...///////////////////////////////////////////////////
     $query6 = "SELECT * FROM `membership` WHERE `id`='$user_id'";
     $result6 = mysql_query($query6);     
     $row = mysql_fetch_array($result6);
     
     $poster_id = $row['id'];
     $poster_name = $row['username'];
     $poster_avatar = $row['avatar'];
     $poster_class = $row['user_class'];
     
     // start making a table:)...////////////////////////////////////////////////////////
     echo '<table width="60%" border="1" bordercolor="#000000" cellspacing="0" cellpadding="0" />
           <tr>
           <td colspan="2" align="left" /> <a href="user_details.php?id='.$poster_id.'" />'.$poster_name.'</a> - (<b>'.$poster_class.'</b>) - <font size="1" />Posted On: '.$post_date.'</font> ';  
           // edit button for the users post...//////////////////////////////////////////
           if($user_id == $poster_id) {
           
              echo "EDIT";
           
           }         
     echo ' </td>
            </tr>
            <tr>
            <td width="20%" align="center" /><img src="avatars/'.$poster_avatar.'" /></td><td width="40%" align="left" valign="top"/>'.$post_body.'</td>
            </tr><br />';
              
     }            
     echo '</table><br />';
     
     } else {
                         
        echo "<b>No Replies Yet :-(</b><br /><br />";
        
     
     }
     
      // add a comment link...////////////////////////////////////////////////////////////
      echo "<b><center>[<a href=\"add_reply.php?id=$topic_post_id\" />Add A Reply</a>]</center></b><br />";
?>

 

thanks as usual for the help guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/54040-solved-basic-forum-code-question/
Share on other sites

Hi Mate,

 

think i solved it, the session/cookie is $member so i did:

 

           // edit button for the users post...//////////////////////////////////////////
           if($member == $poster_name) {
           
              echo "EDIT BUTTON HERE";
           
           }   

 

and it seems to work ok :)

 

Thanks mate

 

Graham

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.