Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

376
Views
Sending variable value to php from Unity

I have a php file which is used to display a pdf file. The pdf file contains variables obtained from php file given below.

$areaOfCircle;
...
...
$pdf->WriteFixedPosHTML($areaOfCircle, 20, 50, 20, 50, 'auto');

And I have my Unity script here

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SendToServer: MonoBehaviour
{
    public string areOfCircle;
   
    IEnumerator Start()
    {
        WWWForm form = new WWWForm();
        form.AddField("areaOfCircle", areOfCircle);
        UnityWebRequest www = UnityWebRequest.Get("https://localhost/sqlconnect/myFirstPhp.php");
        yield return www.SendWebRequest();
        if (www.isNetworkError || www.isHttpError)
        {
            Debug.LogError(www.error);
        }
        else
        {
            Debug.Log("Sent");
        }
    }
}

I am trying to send value of the string to php from Unity but I only get error message. What am I doing wrong here?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Well, you are not sending your form or any data at all.

If you want to use POST then it should rather be UnityWebRequest.Post

UnityWebRequest www = UnityWebRequest.Post("https://localhost/sqlconnect/myFirstPhp.php", form);

If your PHP however actually expects GET then you would probably rather do

UnityWebRequest www = UnityWebRequest.Get($"https://localhost/sqlconnect/myFirstPhp.php?areaOfCircle={areOfCircle}&someSecondParameter{secondParameter}");

Don't see unfortunately how exactly you are setting the $areaOfCircle variable in your PHP code ...

over 4 years ago · Santiago Trujillo Report

0

You can add more variables in the url separated by the & char

UnityWebRequest.Get($"https://localhost/sqlconnect/myFirstPhp.php?areaOfCircle={areaOfCircle}&secondVariable={secondValue}");

In PHP you get them with

$areaOfCirle = $_GET["areaOfCircle"];
$secondVariable = $_GET["secondVariable"];
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!