ambition13 Posted December 19, 2006 Share Posted December 19, 2006 Hello,I have the same files on 2 servers, one server is running php 4.3.2 and the code works. The newer server is running 4.4.3 and the same code does not work.The code is as follows: foreach ($fav_people as $name=>$more) { foreach ($more as $people_id=>$value) { if ($people_id != 0) { $INSERT = "INSERT INTO favorites (user_id, fav_type, id) VALUES ('$_USER[user_id]', '2', '$people_id')"; $iresult = mysql_query($INSERT); } }On the newer server, it gives the following error:Warning: Invalid argument supplied for foreach() in _db_functions.php on line 157This warning shows up 4 times for that line. Anyone have any suggestions on how to troubleshoot this?Thanks in advance.ambition13 Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/ Share on other sites More sharing options...
trq Posted December 19, 2006 Share Posted December 19, 2006 Where is $fav_people being defined? Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/#findComment-144812 Share on other sites More sharing options...
alpine Posted December 19, 2006 Share Posted December 19, 2006 I think it is screaming about the second while,I cannot see the need for the second while either, test:[code]<?php$fav_people = array( 1 => "John", 2 => "Fred");foreach ($fav_people as $people_id => $value) {if ($people_id != 0) { $INSERT = "INSERT INTO favorites (user_id, fav_type, id) VALUES ('$_USER[user_id]', '2', '$people_id')"; echo $INSERT;}}?>[/code]But it sertainly smells a register_globals issue Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/#findComment-144816 Share on other sites More sharing options...
ambition13 Posted December 19, 2006 Author Share Posted December 19, 2006 It is being defined in another file with this:$fav_people = unserialize($_USER[fav_people]);Neither server has register globals turned on (including the one where the code works). Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/#findComment-144819 Share on other sites More sharing options...
trq Posted December 19, 2006 Share Posted December 19, 2006 [quote]It is being defined in another file[/quote]I assume you meen an included file? Place this, just prior to the code you have posted.[code=php:0]print_r($fav_people);[/code]Also... where might this $_USER array be defined. Thats a pretty poor naming convention IMO, its a little confusing. Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/#findComment-144823 Share on other sites More sharing options...
ambition13 Posted December 19, 2006 Author Share Posted December 19, 2006 Yes, an included file. I inherited this code so I am not sure of all the naming conventions yet.Here is the output of the print_r:Array ( [1] => Tom hanks [2] => [3] => [4] => [Tom Hanks] => Array ( [16937] => Array ( [birthdate] => 1956-07-09 [image] => mf ) ) ) Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/#findComment-144831 Share on other sites More sharing options...
ambition13 Posted December 21, 2006 Author Share Posted December 21, 2006 Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/#findComment-145609 Share on other sites More sharing options...
trq Posted December 21, 2006 Share Posted December 21, 2006 Try...[code=php:0]foreach ($fav_people as $name) { foreach ($name as $people_id=>$value) {[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/#findComment-145614 Share on other sites More sharing options...
ambition13 Posted December 21, 2006 Author Share Posted December 21, 2006 Tried that, same error...any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/#findComment-145666 Share on other sites More sharing options...
trq Posted December 21, 2006 Share Posted December 21, 2006 $more isn't an array. Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/#findComment-145677 Share on other sites More sharing options...
ambition13 Posted December 21, 2006 Author Share Posted December 21, 2006 Ok, I have narrowed the problem down further.The error is coming from the following code:function update_fav_people($fav_people) { global $_USER; $DELETE = "DELETE FROM favorites WHERE user_id = '$_USER[user_id]' and fav_type = '2'"; $dresult = mysql_query($DELETE); if ($fav_people) { natksort($fav_people); foreach ($fav_people as $name=>$more) { if ($more) { foreach ($more as $people_id=>$value) { if ($people_id != 0) { $INSERT = "INSERT INTO favorites (user_id, fav_type, id) VALUES ('$_USER[user_id]', '2', '$people_id')"; echo $INSERT; $iresult = mysql_query($INSERT); } } } } $UPDATE = "UPDATE users SET fav_people = '" . addslashes(serialize($fav_people)) . "' WHERE user_id = '$_USER[user_id]'"; echo $UPDATE; $uupdate = mysql_query($UPDATE); } else { $UPDATE = "UPDATE users SET fav_people = '' WHERE user_id = '$_USER[user_id]'"; $uupdate = mysql_query($UPDATE); }}When running the UPDATE code, it inserts extra data. The Mysql record then looks like this: a:5:{i:1;s:13:"Julia Roberts";i:2;s:0:"";i:3;s:0:"";i:4;s:0:"";s:13:"Julia Roberts";a:1:{i:8483;a:2:{s:9:"birthdate";s:10:"1967-10-28";s:5:"image";s:2:"mf";}}}It should just look like this:a:1:{s:13:"Julia Roberts";a:1:{i:8483;a:2:{s:9:"birthdate";s:10:"1967-10-28";s:5:"image";s:2:"mf";}}}Again I inherited this code and am just trying to make it work. How can I rewrite the above function so that it doesn't insert the extra data?Thanks again for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/31293-code-works-on-one-server-but-not-another/#findComment-146021 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.