Oliver Sradnick Oliver Sradnick - 1 year ago 119
C# Question

Unity, PHP, Sql Update

Im realy new into PHP,SQL and im trying to learn How to with Unity.

First i created a new Table in my Database with Unity wich worked Ok.
Now i want to Update this Table with some infos,these infos should come from Unity.
But its not working im not sure if its my C# script or my PHP script.
Add First a snipped from my C# script

IEnumerator InsertMemberData(string username,string day,int sale)
//insert data to table
WWWForm form = new WWWForm();
form.AddField("usernamePost", username);
form.AddField("currentDayPost", day);
form.AddField("daySalePost", sale);

UnityWebRequest www = UnityWebRequest.Post(updateDataTable, form);

yield return www.Send();

if (www.isError)
Debug.Log("Form upload complete!");

and now my PHP script


$servername = **********
$server_username = ***************
$server_password = ****************
$dbName = *****************

$username = $_POST["usernamePost"];
$currentDay = $_POST["currentDayPost"];
$daySale = $_Post["daySalePost"];

//Make Connection
$conn = new mysqli($servername, $server_username, $server_password, $dbName);
//Check Connection
die("Connection Failed". mysqli_connect_error());

$sql = "Update tbl_{$username} SET ".$currentDay." = ".$daySale." WHERE id=1";
$result = mysqli_query($conn, $sql);

echo "there was an Error!";
else echo "Evereything ok.";

i just want to send in a specific Table at a specific day a number.

Answer Source

I rethinked my work. So no table for every user, only on Table with all user/userinfos and thinks a want to save/load. C# script is more or less the same..

IEnumerator InsertMemberData(string username,string day,int sale)


IEnumerator InsertMemberData(string username,string day,**string** sale)

and my PHP script :

    $sqlCheck = "SELECT ID FROM userinfo WHERE username = '".$username."' ";
    $resultCheck = mysqli_query($conn,$sqlCheck);

            $sqlUpdate = "UPDATE userinfo SET {$day} = '".$value."' WHERE username = '".$username."' ";

            $resultUpdate = mysqli_query($conn,$sqlUpdate);

                echo("Update success");
                echo("Update Failed");
        echo("There was an Error.");

Im not realy sure why, but this worked perfect for me. the for the Help @Fred -ii-

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download