LethPhaos Posted March 22, 2012 Share Posted March 22, 2012 There's probably an obvious reason but I can't seem to find it... I start with the $_POST array, received from a form: array(9) { ["Name"]=> string(3) "KTN" ["SQLServer"]=> string(24) "10.6.11.20\VSQLI028,1433" ["Username"]=> string(2) "GF" ["Password"]=> string(2) "GF" ["MasterDB"]=> string(11) "GFMaster_KN" ["Version"]=> string(3) "4.9" ["Prod"]=> string(1) "1" ["Monitored"]=> string(1) "0" ["button"]=> string(38) "updateColumnName=EnvironmentID;Value=1" } I get the button value from the array, and unset the button array value. function load_POST($name) { //returns value and removes it from $_POST array. returns NULL if not existing. $debug = 0; if ( $debug == 1 ) { $backtrace = backtrace(); echo __FUNCTION__."()"; echo " <i>called by ".basename($backtrace[1]['file'])."</i><br/>\n"; } $post = NULL; if( array_key_exists($name, $_POST) ) { $post = urldecode($_POST[$name]); if ( $debug == 1 ) { echo "post $name, value: $post<br/>\n"; } } else { if ( $debug == 1 ) { echo "post $name: doesn't exist<br/>\n"; } } unset($_POST[$name]); return $post; } $_POST is now: array( { ["Name"]=> string(3) "KTN" ["SQLServer"]=> string(24) "10.6.11.20\VSQLI028,1433" ["Username"]=> string(2) "GF" ["Password"]=> string(2) "GF" ["MasterDB"]=> string(11) "GFMaster_KN" ["Version"]=> string(3) "4.9" ["Prod"]=> string(1) "1" ["Monitored"]=> string(1) "0" } Then I create the object to assign the values to: object(Environment)#1 (9) { ["EnvironmentID"]=> NULL ["Name"]=> NULL ["SQLServer"]=> NULL ["Username"]=> NULL ["Password"]=> NULL ["MasterDB"]=> NULL ["Version"]=> NULL ["Prod"]=> int(0) ["Monitored"]=> int(0) } So far so good Then, for each remaining $_POST value, I update the Object accordingly: First one, parametername: Name, parameter: KTN object(Environment)#1 (10) { ["EnvironmentID"]=> NULL ["Name"]=> string(3) "KTN" ["SQLServer"]=> NULL ["Username"]=> NULL ["Password"]=> NULL ["MasterDB"]=> NULL ["Version"]=> NULL ["Prod"]=> int(0) ["Monitored"]=> int(0) ["ColumnName=EnvironmentID;Value=1"]=> object(stdClass)#3 (1) { ["ColumnName"]=> string(1) "1" } } And there we have the problem, for some reason the button value is added to the object somehow... Any ideas? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/259503-weird-issue-while-setting-object-parameters-from-_post-array/ Share on other sites More sharing options...
LethPhaos Posted March 22, 2012 Author Share Posted March 22, 2012 When copying $_POST to a new var $post and using that new var to do the rest of the processing doesn't help... Quote Link to comment https://forums.phpfreaks.com/topic/259503-weird-issue-while-setting-object-parameters-from-_post-array/#findComment-1330239 Share on other sites More sharing options...
LethPhaos Posted March 23, 2012 Author Share Posted March 23, 2012 solved, issue was in one of my other functions, a nights sleep does wonders I'm going to rewrite it anyway, to work the other way around: start from object and get each value from the $_POST array, this will be safer Quote Link to comment https://forums.phpfreaks.com/topic/259503-weird-issue-while-setting-object-parameters-from-_post-array/#findComment-1330442 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.