php mysql + create a friend request system -
i creating friend request system allow user send request each other add friends facebook , have 2 conditions if :
- the user profile owner can not add him self echo error msg
- the user not owner of profile echo message wait request send
if user has send request echo message infor user request had been send.
but error in first condition because system display user owner profile wrong
can me ??
this chunk of code
function addasfriend(a,b){ //alert("member id:" + + "request friendship memeber id:" + b); var url = "script_for_profile/request_as_friend.php"; $("#add_friend").text("please wait...").show(); $.post(url,{request:"requestfreindship",mem1:a,mem2:b},function(data){ $("#add_friend").html(data).show().fadeout(12000); }); } <div class="interactcontainers" id="add_friend"> <div align="right"><a href="#" onclick="return false" onmousedown="javascript:toggleinteractcontainers('add_friend');">cancel</a></div> add <?php echo $username ?> friend? <a href ="#" onclick="return false" onmousedown="javascript:addasfriend(<?php echo $_session['user_id']; ?>,<?php echo $userid; ?>);">yes</a>
request_as_friend.php
<?php //var need both members $mem1=preg_replace('#[^0-9]#i','',$_post['mem1']); $mem2=preg_replace('#[^0-9]#i','',$_post['mem2']); if(!$mem1||!$mem2) { echo "error .missing data"; exit(); } if($mem1==$mem2) { echo "error can not add friend"; exit(); } require_once('../include/connect.php'); if($_post['request']=="requestfriendship") { //check there not request pending viewer requesting profile owner $sql = mysql_query("select id friend_requests mem1='$mem1' , mem2='$mem2'limit1")or die(mysql_error()); $numrows = mysql_num_rows($sql); if($numrows > 0) { echo "you have friend request pending member. must approve when view request list"; exit(); } //check there not request pending profile owner not requesting viewer $sql = mysql_query("select id friend_requests mem1='$mem2' , mem2='$mem1'limit1")or die(mysql_error()); $numrows = mysql_num_rows($sql); if($numrows > 0) { echo "this user has requested friend already! check friend request on profile"; exit(); } $sql = mysql_query("insert friend_requests(mem1,mem2,timedate) values('$mem1','$mem2',now())") or die (mysql_error("friend request insertionn error")); //$sql = mysql_query("insert pms(to,from,time,sub,msg) values('$mem2','xxxxx',now(),'new friend request','you have new friend request waiting approval.<br /><br />navigate profile , check friend request.<br /><br />thank you.')") or die (mysql_error("friend request pm insertionn error")); echo "friend request sent succesfully. member must approve request"; exit(); } ?>
what post array returns mem1 , mem2?
however, shouldn't compare post data. or not both.
for example have logged in, id stored in session. opening user profile i.e.: http://yoursite.com/viewprofile.php?id=1001 . after passing jquery should check in php smth like:
if ($_get['id'] = $_sessiom['id']) { //you cannot add }
Comments
Post a Comment