Jump to content

[SOLVED] Querying database for info


graham23s

Recommended Posts

Hi Guys,

 

what i'm trying to do here is make the "message me" button dissapear IF the logged in users is viewing theyre own profile (basically so people can't message them self)

 

hers the code i have:

 

           <td width="200" align="right">About Me</td><td align="left">'.$about_me.'</td>
           </tr>
           <tr>
           <td width="200" align="right">Actions</td><td align="center">(<a href="add_friend.php?id='.$id.'">Add To Friends</a>)</td>
           </tr>
           <tr>
           <td colspan="2" align="center">';
           // make a query to see if the logged in user has access to the message me button.../
           $query4 ="SELECT * FROM `membership` WHERE `id`='$id'";
           $result4 = mysql_query($query4) or die (mysql_error());
           $rows = mysql_fetch_array($result4) or die (mysql_error());
           
           //$row_to_match = $rows['id'];
           
           if(mysql_num_rows($result4)) {
           
              echo '<input type="submit" name="submit" value="Send Message To '.$username.'" />';
           
           } else {
           
              echo "";
           
           }           
           
           //<input type="submit" name="submit" value="Send Message To '.$username.'" />
           
   echo '  <input type="hidden" value="'.$id.'" />
           </td>
           </tr>
           </table></form><br />';

 

can nayone point me in the right direction on what i'm doing wrong?

 

cheers guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/52051-solved-querying-database-for-info/
Share on other sites

Why not just make it so when they send the message it checks if they sent it to themselves. You would obviously have the persons ID they are trying to message, so you can do a check agains the ID's with that info.

 

<?php

//the person they are trying to message, ID is coming from the message form they filled out
$id = $_POST['id'];

//Now check that ID against their ID
if ($id == $user_id){
   echo "You can't message yourself!";
exit;

} else {

   //go on with allowing them to message the person
}

?>

 

I am assuming you have their ID stored in a session, and that is where I pulled the "$user_id" variable from.

 

 

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.