Hey!
I would like to make a lua script that would take some text from a couple of derma text boxes and put the text from the boxes into an SQL table. How would I go about doing this? Is there a way to send a GET to a .php file in lua? I could make a .php file to do all the SQL work for me on a web server and just make the lua script send a GET request to the .php file. Is this possible in LUA? If not do you think packets would be an option?
Thanks!
You can use a module like tmysql or mysqloo.
[QUOTE=Chizbang;40384369]Is there a way to send a GET to a .php file in lua?![/QUOTE]
Yep, [url]http://wiki.garrysmod.com/page/http[/url]
Awesome! Thanks for the link. Finally some progress on this!
Tried this:
[lua]http.Post( "localhost/motd/index.php", "dontknowhowtodothis", onSuc(),onFail() )[/lua]
When I go to run it i get this error:
data/luapad/test.txtdata/luapad/test.txtdata/luapad/test.txtdata/luapad/test.txtdata/luapad/test.txt
[ERROR] RunString:48: unexpected symbol near '{'
ing:48: unexpected symbol near '{'
1. unknown - RunString:0
[editline]23rd April 2013[/editline]
Derp, I was in Objective C mode and made an Objective C method -_-
Ok. How do I pass multiple parameters to my POST php file?
Thanks!
Also the request goes through fine according to my onSuc method but it doesnt work because nothing appears in my sql table. It will do an SQL query wether or not it didnt send any parameters because I tested it in my browser. Something wrong with how I have done it?
Thanks!
Don't use POST, use GET and then do link?something=whatever
Dont think theres a way to do a GET request in lua. The POST request i did doesnt do anything at all despite my onSuc method telling me it works when it doesnt... Weird.[QUOTE=>>oubliette<<;40387808]Don't use POST, use GET and then do link?something=whatever[/QUOTE]
[editline]23rd April 2013[/editline]
Oh wait, it calls both the fail method and the suc method..... Wtf
http.Post( string url, table parameters, function onSuccess, function onFailure )
If you can see there is a "table parameters" that are the things to post on your site if you mean that. If you need multiple posts.
So you need to make table that there is your needed posts in it, sorry im bit bad in teaching things hope you understand :)
But i still recommend you to use mysql library for it like mysqloo.
[code]
<?php
if ( isset( $_GET[ 'nameOfData' ] ) ) {
echo "nameOfData = " . $_GET[ 'nameOfData' ];
}
else {
echo "no variable 'nameOfData' was passed through the _GET variable!";
}
?>
[/code]
[lua]
http.Fetch( "myurl?nameOfData=use_this_if_youre_not_passing_important_data", function() print( "yup, worked"); end, function() print("shitt!111!1111!1"); end );
[/lua]
[editline]23rd April 2013[/editline]
Also, your post request didn't work because the callback functions you used had brackets on them, that would be passing whatever that function returned to the http.Post function rather than the function itself.
Thanks man! Worked beautifully. One question though... How do I combine 2 strings together?
Like:
[lua]http.Fetch("http://blahblah/blahbkah/sql.php?" then right here I want text from a text box.... )[/lua]
I have tried stuff like "blahblah/blahblah/sql.php?"."ttest" or "blahblah/blahblah/sql.php?" && "test" to no avail. Thanks!
[QUOTE=Chizbang;40389042]Thanks man! Worked beautifully. One question though... How do I combine 2 strings together?
Like:
[lua]http.Fetch("http://blahblah/blahbkah/sql.php?" then right here I want text from a text box.... )[/lua]
I have tried stuff like "blahblah/blahblah/sql.php?"."ttest" or "blahblah/blahblah/sql.php?" && "test" to no avail. Thanks![/QUOTE]
Single dots/full stops/periods are used for PHP, in Lua we use two.
[lua]
local hello = "hello";
local space = " ";
local world = "world";
print( hello .. space .. world .. "!" );
[/lua]
result : hello world!
I simple google search "concatenate strings in lua" would have sufficed.
Thanks works perfect!
Sorry, you need to Log In to post a reply to this thread.