Lua PHP Post call

If someone would be kind enough can you post an example of Lua making call to to post data to a php script.

For example say I have php script on my web server as:
[php]Welcome <?php echo $_POST["fname"]; ?>!
[/php]
How can I use Lua to send a string with the value Joan?

As a plus how would I update my php script to also return the age of Joan assuming she is 85?

I’m having trouble figuring this out. I tried to piece it together with general php code, but can’t figure it out with Lua

Thanks! [import]uid: 10640 topic_id: 4452 reply_id: 304452[/import]

I updated my php script to use $_GET instead of $_POST and was able to Welcome Joan! if my request looks like http://somesite.com/script.php?fname=Joan.

I’m still interested on getting some info on getting values back and how others are sending data to php and getting it back.

Thanks again

Bob [import]uid: 10640 topic_id: 4452 reply_id: 13899[/import]

Ok, now that I was able to have 1 hour without a biting and pinching 1 year old on my lap I think I figured out a way to do this:).

My goal is to interface with a centralized database such as PostgreSQL to work on a multi-player drum role… tic tac toe game my daughter and I are working on. So if you have a Lua script with the contents below and a php script with the contents below I think it should work. Thanks to ehsmeng for this post to get me started [html]http://developer.anscamobile.com/code/post-json-data-and-receive-json-data-example[/html]

–START LUA
[lua]http = require(“socket.http”)

ltn12 = require(“ltn12”)
url = require(“socket.url”)
local post = “InputName=” … “Robot7001”
post = post … “&InputAge=” … “8”
local response = {}

local r, c, h = http.request {
url = "https://www.yoursite.com/TestPost.php?",
method = “POST”,
headers = {
[“content-length”] = #post,
[“Content-Type”] = “application/x-www-form-urlencoded”
},
source = ltn12.source.string(post),
sink = ltn12.sink.table(response)
}
print(response[1])[/lua]
–START PHP
[php]

<?php
if ( $\_POST[InputAge] \<= 30 ) echo ("You young " . $\_POST[InputName] . "." ); else echo ("You getting old" . $\_POST[InputName] . "!" ); ?\> [/php] Hopefully this will be of value to someone wanting to talk to a php script or any web hosted script for that matter. At some point sending json or some other speced data will probably be a good idea and should be pretty easy with Lua and PHP. I know for me this is one step closer to taking over the world with multi-player tic tac toe! [import]uid: 10640 topic\_id: 4452 reply\_id: 13955[/import]

Hi there,

this looks great. Did you also succeed in uploading binary files, e.g. images or zip-archives?
Desperately seeking for a solution…

Bye,
Jörg [import]uid: 5420 topic_id: 4452 reply_id: 20164[/import]

This worked great but how would you do this with network.request() instead? [import]uid: 24111 topic_id: 4452 reply_id: 79023[/import]