Jump to content

minor error!


Glenskie

Recommended Posts

ok , this is to request someone to be your friend and i keep getting an error saying "mysql_error() expects parameter 1 to be resource" i dont know what is wrong , it worked before ... please help.

<?php

if ($_POST["request"] == "requestFriendship") {

    $mem1 = preg_replace('#[^0-9]#i', '', $_POST['mem1']); 
    $mem2 = preg_replace('#[^0-9]#i', '', $_POST['mem2']); 
//
if (!$mem1 || !$mem2 || !$thisWipit) {
	echo  'Error: Missing data';
    	exit(); 
}
//
if ($mem1 == $mem2) {
    	echo  'Error: You cannot add yourself as a friend';
    	exit(); 
} 


//See if already friends
$sql1 = "SELECT id FROM friends WHERE mem2='$mem1' AND mem1='$mem2' LIMIT 1";
$result1 = mysql_query($sql1) or die (mysql_error("sql1 failed")); 
$data1 = mysql_fetch_row($result1);
    if ($data1[0]) {
	echo  'This member is already your Friend'; 
	exit(); 
}
//Check if user already requested to be friends
$sql2 = "SELECT id FROM friends_requests WHERE mem1='$mem1' AND mem2='$mem2' Limit 1";
$result2 = mysql_query($sql2) or die (mysql_error("sql2 failed")); 
$data2 = mysql_fetch_row($result2);
    if ($data2[0]) {
	echo '<img src="images/round_error.png" width="20" height="20" alt="Error" /> You have a Friend request pending for this member. Please be patient.';
        exit(); 
}
//Check if friend already requested to be friends
$sql3 = "SELECT id FROM friends_requests WHERE mem1='$mem2' AND mem2='$mem1' Limit 1";
$result3 = mysql_query($sql3) or die (mysql_error("sql3 failed"));  
$data3 = mysql_fetch_row($result3);
    if ($data3[0]) {
	echo '<img src="images/round_error.png" width="20" height="20" alt="Error" /> This user has requested you as a Friend already! Check your Requests on your profile.';
        exit(); 
}
//If still here make insert	
$mem1=mysql_real_escape_string($mem1);
$mem2=mysql_real_escape_string($mem2);
$sql = mysql_query("INSERT INTO friends (mem1, mem2, timedate) VALUES('$mem1','$mem2',now())") or die (mysql_error("Friend Request Insertion Error"));
echo '<img src="images/round_success.png" width="20" height="20" alt="Success" /> Friend request sent successfully. This member must approve the request.';
    exit(); 
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.