Jump to content

script is not working


ohdang888

Recommended Posts

Okay, so i want this script to write the "id of the new friend" in the first column of the table that has "0" has the value in it.

 

right now, its overwriting the info in column 1, despite the fact that column 1 had a "1" in it (not a "0")

 

the problem is probably near the bottom of the script

<?php
if($action == 'accept'){

$result = mysql_query("SELECT `{$field}` FROM `friend_requests` WHERE `id`='{$id}'") or die(mysql_error());
$new_friends = mysql_fetch_array($result);

$new_friend_id = $new_friends[$field];

$y = 1;// used for getting info from the right column
$empty = 1;


$result = mysql_query("SELECT * FROM `user_friends` WHERE `id`='{$id}'") or die(mysql_error());
$friends = mysql_fetch_array($result);

if($friend['1'] != 0){
$empty++;
$y++;
if($friend['2'] != 0){
	$empty++;
	$y++;
	if($friend['3'] != 0){
		$empty++;
		$y++;
		if($friend['4'] != 0){
			$empty++;
			$y++;
			if($friend['5'] != 0){
				$empty++;
				$y++;
			}
		}
	}
}
}



mysql_query("UPDATE `user_friends` SET `{$empty}` = '{$new_friend_id}' WHERE `id`='{$id}' ") or die(mysql_error());
mysql_query("UPDATE `friend_requests` SET `{$field}` = '0' WHERE `id`='{$id}' ") or die(mysql_error());
echo'Friend Successfully Added!<br>';
echo 'Check out their profile <a href="../profile.php?id=';
echo $new_friend_id;
echo '">here</a>';
}
?>

Link to comment
Share on other sites

You are defining friends here

 

$friends = mysql_fetch_array($result);

 

 

and using friend without the s in the rest of the script.

 

if($friends['1'] != 0){

$empty++;

$y++;

if($friends['2'] != 0){

$empty++;

$y++;

if($friends['3'] != 0){

$empty++;

$y++;

if($friends['4'] != 0){

$empty++;

$y++;

if($friends['5'] != 0){

$empty++;

$y++;

}

}

}

}

}

 

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.