Kevin1003 Posted February 21, 2016 Share Posted February 21, 2016 I want to make a player list with the SDK. ERROR: Notice: Undefined variable: players in C:\xampp\htdocs\mta\call.php on line 12 Notice: Undefined variable: players in C:\xampp\htdocs\mta\call.php on line 12 SERVER.LUA: addEventHandler("onGamemodeMapStart", getRootElement(), function(theMap) end) function getPlayersName() local playerslist = {} for i,p in ipairs (getElementsByType("player")) do local thep = string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "") table.insert(playerslist,tostring(thep)) end return playerslist end PHP FILE: <?php include( "sdk/mta_sdk.php" ); // Vide la table $sql = 'DELETE FROM server_players'; mysql_query($sql); $x = 0; $start = 0; while($x <= $players) { $start = $start+1; if(isset($playerlist[$start])){ $sql = 'INSERT INTO server_players VALUES("", "'.$playerlist[$start].'", "Guest", "Guest")'; mysql_query($sql); } $x++; } ?> DATABASE: COLUMNS: ID (INT) (AUTO INCREMENT) PLAYER (TEXT) Link to comment
therainycat Posted February 21, 2016 Share Posted February 21, 2016 Please provide the C:\xampp\htdocs\mta\call.php file. There's no $players on line 12 of the code provided by you, probably you've posted a different file Link to comment
Simple0x47 Posted February 21, 2016 Share Posted February 21, 2016 I want to make a player list with the SDK.ERROR: Notice: Undefined variable: players in C:\xampp\htdocs\mta\call.php on line 12 Notice: Undefined variable: players in C:\xampp\htdocs\mta\call.php on line 12 SERVER.LUA: addEventHandler("onGamemodeMapStart", getRootElement(), function(theMap) end) function getPlayersName() local playerslist = {} for i,p in ipairs (getElementsByType("player")) do local thep = string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "") table.insert(playerslist,tostring(thep)) end return playerslist end PHP FILE: <?php include( "sdk/mta_sdk.php" ); // Vide la table $sql = 'DELETE FROM server_players'; mysql_query($sql); $x = 0; $start = 0; while($x <= $players) { $start = $start+1; if(isset($playerlist[$start])){ $sql = 'INSERT INTO server_players VALUES("", "'.$playerlist[$start].'", "Guest", "Guest")'; mysql_query($sql); } $x++; } ?> DATABASE: COLUMNS: ID (INT) (AUTO INCREMENT) PLAYER (TEXT) It's clear, you haven't defined players. In the SDK it's not defined that's why the script show's you error. If you could gave the call.php script, I could define for you players. Link to comment
tosfera Posted February 22, 2016 Share Posted February 22, 2016 Please provide the C:\xampp\htdocs\mta\call.php file.There's no $players on line 12 of the code provided by you, probably you've posted a different file even if he did post the right file, it's line 9. But then again, Simple01 already said what's wrong. The $players has never been defined in the given files nor has there been a call towards the server to get the playernames. Link to comment
Kevin1003 Posted February 22, 2016 Author Share Posted February 22, 2016 I edit the script and it works fine but the server don't send the user on the database. RESOURCE START ERROR: [19:32:14] Starting mta_php [19:32:14] WARNING: [tutorial]\mta_php\server.lua:1: Bad argument @ 'getElementData' [Expected element at argument 1, got nil] [19:32:14] WARNING: [tutorial]\mta_php\server.lua:2: Bad argument @ 'getElementData' [Expected element at argument 1, got nil] [19:32:14] WARNING: [tutorial]\mta_php\server.lua:3: Bad argument @ 'getPlayerName' [Expected element at argument 1, got nil] [19:32:14] WARNING: [tutorial]\mta_php\server.lua:5: Access denied @ 'callRemote' [19:32:14] mta_php restarted successfully SERVER.LUA: local serial = getElementData(player, "serial") local id = getElementData(player, "id") local player = getPlayerName(player) callRemote("http://www.localhost/mta/sdk/player.php", result, serial, id, player) PLAYER.PHP (DISPLAYING THE DATA) <?php include( "mta_sdk.php" ); $base = mysql_connect ('localhost', 'root', ''); mysql_select_db ('mta', $base); $sql = 'SELECT * FROM server_players'; $req = mysql_query($sql); while($data = mysql_fetch_array($req)){ $playername = $data['player']; $id = $data['id']; $serial = $data['serial']; echo "<b>$playername</b><br /> serial: $serial<br /> ID: $id<br />"; } mysql_close(); ?> TEST.PHP (MYSQL CONNECTION) <?php include( "mta_sdk.php" ); $table = mta::getInput(); $serial= $table[0]; $id = $table[1]; $player = $table[2]; // Send infos in MySQL $base = mysql_connect ('localhost', 'root', ''); mysql_select_db ('mta', $base); $sql = 'INSERT INTO server_players VALUES("$player", "'.$serial.'", "'.$id.'") '; mysql_query($sql); mysql_close(); // Return true if is added mta::doReturn(true); ?> DATABASE COLUMNS: id int(11) serial int(11) player text Link to comment
GTX Posted February 22, 2016 Share Posted February 22, 2016 1. It means that player variable is not defined. 2. Put mta_php resource in ACL under Admin group. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now