Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

378
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda