Well, Bill, I always try to look at the problem logically… Here is what I see in your system…
First, you scan thru the posted data which is an array of data.
During that loop, you copy the data already in an array and place into another array.
Next, you call a function to take the second array and create URL’s from ONE and only one item in it.
Does that make sense to you?
Now, you check if the submit button is pressed. Then, if it is, you parse thru the $_POST array and create
a new one. Why? Why not just use the $_POST array as it is already there. Place your function code in
that loop and there is no need to call a function. Since you pull the $key and $value out of the $_POST
array, you already have them to run thru the function code with.
Restoring an array into another, then calling a function that takes the values out of the second array is just
a waste of server resources. It just does not make sense to me why you would want to do that…
Perhaps I do not understand some other reason for this code…
Without the extra array(s) and the function, your submit button code would be just:
if(isset($_POST[‘Submit’]))
{
foreach($_POST as $key => $value)
{
if(!empty($value) && ($value != “Submit”))
{
// code from your function…
$url = DOMAIN.FOLDER.APIPATH . $resourcename.rawurlencode("/" . $key);
// Create cURL
$ch = curl_init($url);
// Set URL and other options
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array ('content-type: application/json'));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'PUT',$output);
curl_setopt($ch,CURLOPT_POSTFIELDS,$output);
// Pass URL to browser
curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE);
}
}
No need for calling a function and hashing out inputs in a new array…
$result = update($idValues, $values, $tableName);
Not sure of your CURL code. But, this makes more sense to me. The other way would be to call your
function code for each of the posted entries, not the entire array of them… To do that, it would be like:
if(isset($_POST[‘Submit’]))
{
foreach($_POST as $key => $value)
{
if(!empty($value) && ($value != “Submit”))
{
$result = update($key, $value, $tableName);
}
}
}
And, then in the function, handle just one ID’s key/value at a time…
Hope this make sense…