Jump to content

help with some php?


Smart.

Recommended Posts

Posted

Okay, so.. the .php only outputs: "Data:" when it's supposed to show "Data: lol"

.lua

function daFunction(thePlayer) 
    setElementData(thePlayer, "data", "lol") 
    data = getElementData(thePlayer, "data") 
    callRemote("http://mywebsite.com/mta//information.php", function() end, data) 
    outputChatBox(data) -- it does output "lol" here. 
end 
addCommandHandler("data", daFunction) 

.php

 <?php 
include( "mta_sdk.php" ); 
$table = mta::getInput(); 
$data = $table[1]; 
  
echo "Data: $data<br />"; 
  
?> 

Posted
In php arrays indexes starts from 0
$data = $table[0];  

but,

 <?php 
include( "mta_sdk.php" ); 
$table = mta::getInput(); 
$data = $table[0]; 
  
echo "Data: $data
"; 
mta::doReturn(true); 
  
?> 

outputs:

Data:

[true]

Posted
function daFunction(thePlayer) 
    setElementData(thePlayer, "data", "lol") 
    data = getElementData(thePlayer, "data") 
    callRemote("http://mywebsite.com/mta//information.php", function(arg1) 
                                                                outputChatBox(arg1) 
                                                            end, data) 
end 
addCommandHandler("data", daFunction) 

Posted

Try

mta::doReturn($data); 

You cant check result via web browser. Because you php script deals only with mta server. If you open it in you browser result always be empty, so echo is useless.

Posted
  
<?php 
    include( "mta_sdk.php" ); 
    $table = mta::getInput(); 
      
    print_r($table); 
  

And post result.

blank page.

Try
mta::doReturn($data); 

You cant check result via web browser. Because you php script deals only with mta server. If you open it in you browser result always be empty, so echo is useless.

result: Data:

[null]

Posted

Ok so this code is tested and works fine for me:

function daFunction(thePlayer) 
    setElementData(thePlayer, "data", "lol") 
    data = getElementData(thePlayer, "data") 
    callRemote("http://127.0.0.1/agtac/index.php", function(arg1) print(arg1) end, data) 
    outputChatBox(data) -- it does output "lol" here. 
end 
addCommandHandler("data", daFunction) 

<?php 
include( "mta_sdk.php" ); 
$table = mta::getInput(); 
file_put_contents('test.txt',$table[0]); 
mta::doReturn($table[0]); 
?> 

Result is printed to server console and to the file test.txt in website directory. Check your script url in callRemote and check resource permissions in acl.xml

PS: Found a strange bug - callRemote in onResourceStart returns true but query does not reach the php script

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...