Search Unity

WWWForms keeps inserting blank values into mySQL

Discussion in 'Scripting' started by Clave, Nov 10, 2010.

  1. Clave

    Clave

    Joined:
    Apr 6, 2010
    Posts:
    24
    Hello everyone, I am trying to insert values from Unity to a PHP then to mySQL. I've tried inserting manually in a browser's address bar and it works fine, but when i use the WWW Form AddField, it connects successfully but inserts nothing, just blank values. I dont really know what's wrong. :(

    Code (csharp):
    1. public class addInfo : MonoBehaviour
    2. {
    3.     private string addInfoURL = "http://myurl.net/addInfo.php";
    4.     private string username1 = "Albert";
    5.     private string info1 = "this is my info";
    6.    
    7.     void Update ()
    8.     {
    9.         if(Input.GetKeyDown("h"))
    10.         {
    11.             WWWForm form = new WWWForm();
    12.             form.AddField("username",username1);
    13.             form.AddField("info",info1);
    14.             WWW www = new WWW(addInfoURL, form);
    15.             StartCoroutine(addInfoToDB(www));
    16.         }
    17.     }
    18.    
    19.     public IEnumerator addInfoToDB(WWW www)
    20.     {
    21.        
    22.         yield return www;
    23.         if (www.error == null)
    24.         {
    25.             Debug.Log("WWW Ok!: " + www.text);
    26.         }
    27.         else
    28.         {
    29.             Debug.Log("WWW Error: "+ www.error);
    30.         }    
    31.     }
    32. }
    Here's my php:

    PHP:
    <?php 
            $db 
    mysql_connect('host''username''pass') or die('Could not connect: ' mysql_error()); 
            
    mysql_select_db('myDB') or die('Could not select database');

            
    $username $_GET['username'];
            
    $info $_GET['info'];
        
            
    $query "insert into myDB values (NULL, '$username', '$info')"
            
    $result mysql_query($query) or die('Query failed: ' mysql_error()); 
    ?>
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    form data will not go through $_GET, that would be part of the url.
    form data enter the php through $_POST
     
  3. Clave

    Clave

    Joined:
    Apr 6, 2010
    Posts:
    24
    It worked! :D thank you very much.