Jump to content

PHP update foreach array error


Monkuar

Recommended Posts

//Update the ranks
if (isset($_POST['update'])){
$ids = implode(",", array_map('intval', $_POST['m']));
$ranks = implode(",", array_map('intval', $_POST['ranks']));
if ($ids < 1)
message("Incorrect Data");
if ($ranks < 0)
message("Incorrect Data");
foreach ($_POST['ranks'] as $muffins){
$db->query('UPDATE friends set rank = '.$muffins.' WHERE friend_id = '.$_POST['m'].' AND user_id = '.$pun_user['id'].'') or error('Unable to remove users from online list', __FILE__, __LINE__, $db->error());
}
redirect("s.php?section=Friends","Thanks, Ranks Updated");
}

 

friend_id = becomes blank? the $muffins work and each rank is showed respectivaly, but how can I join in another array in the loop? I tried another foreach in the loop, but it just made me run double the queries.

 

Any idea? $muffins is working fine and $_POST['m'] is giving no results  i need to have 2 dynamic arrays in that forloop, the $ranks and the $ids

Link to comment
https://forums.phpfreaks.com/topic/258383-php-update-foreach-array-error/
Share on other sites

fixed it

foreach($_POST['ranks'] as $index=>$value)
{
$ranks = mysql_real_escape_string(TRIM($_POST['ranks'][$index])); 
	$ids = mysql_real_escape_string(TRIM($_POST['m'][$index])); 

$db->query('UPDATE friends set rank = '.$ranks.' WHERE friend_id = '.$ids.' AND user_id = '.$pun_user['id'].'') or error('Unable to remove users from online list', __FILE__, __LINE__, $db->error());
}
redirect("s.php?section=Friends","Thanks, Ranks Updated");
}

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.