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
https://forums.phpfreaks.com/topic/94405-script-is-not-working/
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
https://forums.phpfreaks.com/topic/94405-script-is-not-working/#findComment-483517
Share on other sites

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.