Hi everyone!

I have a problem updating my table named 'friend'. This is where I save my friend requests and updates it when a user accepts the request. My problem is when I accept a request, only one query updates. Separately, they work. But when I try to use the two together, it can only execute one query.

$sql = "SELECT Pk_Id FROM signup WHERE email ='$userEmail' ";
$q = mysql_query($sql,$con) or die("Unable to verify user because: " . mysql_error());
$userID = mysql_result($q,0);
	
$sql2 = "SELECT Pk_Id FROM signup WHERE email='$friendRequest'";
$q2 = mysql_query($sql2,$con) or die("Unable to verify user because: " . mysql_error());
$friendID = mysql_result($q2,0);
	
if($_POST['addFriend']){
	
$sql3 = ("UPDATE friend SET isActive=1 WHERE userEmail='$friendRequest' AND friendID='$userID'");
if (!mysql_query($sql3,$con)){
	die('Error: ' . mysql_error());
} else{}
		
$sql4 = ("UPDATE friend SET isActive=1 WHERE userEmail='$userEmail' AND friendID='$friendID'");
if (!mysql_query($sql4,$con)){
	die('Error: ' . mysql_error());
} else{}
}

Recommended Answers

All 3 Replies

I tried it directly i the database and I got this

UPDATE friend SET isActive = '1' WHERE userEmail = 'renz@yahoo.com' AND friendID = '28' AND stat = '1';# MySQL returned an empty result set (i.e. zero rows).

UPDATE friend SET isActive = '1' WHERE userEmail = 'karen@yahoo.com' AND friendID = '29' AND stat = '2';# 1 row(s) affected

but the first query updates isActive to 1..

Submit a complete test case with CREATE TABLE statements and INSERT statements and the queries which do not work as expected. I'm sure that you'll find your error when you prepare the test case.

i really do not understand what you are trying to do.

the query is doing exactly what is it is written for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.