0

Is there anyway I can pass an array constructed in the vba to a php web service??? I have been looking for that with out any success. I do not now if that is possible. So.. what I want to do is: I got a form made in Excel, so I filled it up and then I press a button and stores the data into an dynamic array, an I want to save this in a mysql data base, and I would like to do it by passing the array to a php file to be able to save it in the data base. I will appreciate any help on this! Thanks a lot...

1 Answer 1

1

If you need a PHP script getting the array data via HTTP then the data must be serialized somehow. If you do that the same way a HTML Form would do it, then you can PHP let work the same way it would work with such HTML Form data.

Example:

test/test.php:

<?php
var_dump($_POST);
?>

VBA:

Sub XMLHTTP_Post_Request()

 aDataArray = Array("input1=Hello", "input2=World", "idValue=12345")

 sData = Join(aDataArray, "&")
 Debug.Print sData

 Set oWinHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
 oWinHTTP.Open "POST", "http://test/test.php", False

 oWinHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"

 oWinHTTP.Send sData

 Debug.Print oWinHTTP.ResponseText

End Sub

So the $_POST array in PHP will be:

array(3) {
  ["input1"]=>
  string(5) "Hello"
  ["input2"]=>
  string(5) "World"
  ["idValue"]=>
  string(5) "12345"
}

Note that this example contains only ASCII data. If you have other data, you must urlencode the data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.