Jump to content

If session (userId)


adam87

Recommended Posts

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

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

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.