Unreal script:
class MyPlayerController extends PlayerController;
function SendHTTPRequest(string Nickname, string Color)
{
local string URL;
URL = "http://localhost/update_color.php?nickname=" $ Nickname $ "&color=" $ Color;
HttpRequest(URL, 'GET');
}
function UserInputEvent(string Nickname, string Color)
{
SendHTTPRequest(Nickname, Color);
}
Php:
<?php
$nickname = isset($_GET['nickname']) ? $_GET['nickname'] : '';
$color = isset($_GET['color']) ? $_GET['color'] : '';
$serverName = "localhost";
$connectionOptions = array(
"Database" => "YourDatabaseName",
"Uid" => "YourUsername",
"PWD" => "YourPassword"
);
$conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn === false) {
die('Database connection failed. Error: ' . print_r(sqlsrv_errors(), true));
}
$sql = "UPDATE YourTableName SET Color = '$color' WHERE Nickname = '$nickname'";
$stmt = sqlsrv_query($conn, $sql);
if ($stmt === false) {
die('SQL query execution failed. Error: ' . print_r(sqlsrv_errors(), true));
}
sqlsrv_close($conn);
echo "Color updated successfully for nickname: $nickname";
?>