Jump to content

[SOLVED] Help with db query


mediabob

Recommended Posts

I have a question about the best way to do this.

 

I have a web site where you can put someone on an "invite" list, now when a person posts content only people on this "invite" list can view the content.

 

All of the "invites" are stored in the same table with just the member numbers for the poster and the invited people being changed.

 

So my question is, when the page is loaded, what would be the best way to check the database to see if the member number of the person viewing the page is in the "invite" table??

 

So for example if your member # is 1202, and member # 1504 posted some content it would scan the database for member # 1202 on the invite list of member # 1504.

 

I hope I am being clear about what I am saying here  ???

Link to comment
https://forums.phpfreaks.com/topic/84777-solved-help-with-db-query/
Share on other sites

Something like this should do the trick:

 

<?php
$id1 = $_SESSION['id']; //im assuming you have the currently logged in user's in stored in a session?
$id2 = $_GET['id']; //and the user ID of the posted content in the $_GET array?
$sql = "SELECT COUNT(*) FROM tbl WHERE col1=$id1 AND col2=$id2";
$result = mysql_query($sql) or die(mysql_error());
$num = mysql_result($result,0);
if($num != 1){
echo 'You are not authorised to view this!';
exit;
}
//continue with page
?>

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.