Jump to content

weird issue while setting object parameters from $_POST array


LethPhaos

Recommended Posts

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... :confused: Any ideas?

Thanks in advance!

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.