Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

377
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda