adam87 Posted April 6, 2009 Share Posted April 6, 2009 I'm wanting to add a edit button to my mini message board i've made and basically want it to check the users_id of the current session and if its = to the author of the poster on the message board to have a edit button so they can modify the post. So I was wondering how I would check the current user's id of that session and see if it matches the author. I've currently got it storing the posters ID to my database so i just need it to match to that. <?php session_start(); nclude 'dbc.php'; if (isset ($_SESSION['user'])) { ?> <form action="insert_msg.php" method="post"> <input name="user" type="hidden" value="<? echo $_SESSION['user'] ?>"> <input name="uid" type="hidden" value="<? echo $_SESSION['uid'] ?>"> <select name="band_name"> <? $result = mysql_query("SELECT DISTINCT band_name FROM gigs ORDER BY band_name",$linkme); while($row = mysql_fetch_array($result)) { ?> <option value = "<?php echo $row['band_name'] ?>"> <br /> <? echo $row['band_name'] ?> </option> <? } ?> </select> <p> <textarea name="review" cols="50" rows="5"></textarea> </p> <input name="" type="submit" value="Post Review"> </form> <? } $msgs = mysql_query("SELECT * FROM reviews"); $user_check = mysql_query("SELECT user_id FROM reviews"); while($row = mysql_fetch_array($msgs)) { ?> <table width="500px"> <? echo "<tr>"; echo "<td> Username: " . $row['user_name']. "</td>"; echo "</tr>"; echo "<tr>"; echo "<td> Band Reviewed: " . $row['band_name']. "</td>"; echo "</tr>"; echo "<tr>"; ?> <td class="tdmsg"> <? echo " Review: " . $row['review']. "</td>"; echo "<br />"; echo "</tr>"; if ($_SESSION['uid'] == $user_check) { echo "<tr>"; echo "<td> Edit </td>"; echo "</tr>"; } } echo "</table>"; ?> I've kinda hit a brick wall with this one! Link to comment https://forums.phpfreaks.com/topic/152872-if-session-userid/ Share on other sites More sharing options...
adam87 Posted April 7, 2009 Author Share Posted April 7, 2009 right so i currently have the users id being shown with the user id next to each message, so now I want to be able to do an if statement where if the user id == the session's user idea to show an edit button. Below is my current code, im just struggling to get the if statement working, i've tried a few ways still nothing. <?php include 'dbc.php'; if (isset ($_SESSION['user'])) { ?> <form action="insert_msg.php" method="post"> <input name="user" type="hidden" value="<? echo $_SESSION['user'] ?>"> <input name="uid" type="hidden" value="<? echo $_SESSION['uid'] ?>"> <select name="band_name"> <? $result = mysql_query("SELECT DISTINCT band_name FROM gigs ORDER BY band_name",$linkme); while($row = mysql_fetch_array($result)) { ?> <option value = "<?php echo $row['band_name'] ?>"> <br /> <? echo $row['band_name'] ?> </option> <? } ?> </select> <p> <textarea name="review" cols="50" rows="5"></textarea> </p> <input name="" type="submit" value="Post Review"> </form> <? } $msgs = mysql_query("SELECT * FROM reviews"); while($row = mysql_fetch_array($msgs)) { ?> <table width="500px"> <? echo "<tr>"; echo "<td> Username: " . $row['user_name']. "</td>"; echo "</tr>"; echo "<tr>"; echo "<td> Band Reviewed: " . $row['user_id']. "</td>"; echo "</tr>"; echo "<tr>"; echo "<td> Band Reviewed: " . $row['band_name']. "</td>"; echo "</tr>"; echo "<tr>"; ?> <td class="tdmsg"> <? echo " Review: " . $row['review']. "</td>"; echo "<br />"; echo "</tr>"; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/152872-if-session-userid/#findComment-803026 Share on other sites More sharing options...
9three Posted April 7, 2009 Share Posted April 7, 2009 There is an easier way. In your table where the message is actually stored add another column. name it "author" then just check to see if its the same author, if it is show the edit button else dont show the button Link to comment https://forums.phpfreaks.com/topic/152872-if-session-userid/#findComment-803104 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.