how query same field with several values in mysql from Unity's SendWebRequest

Hey all
I’m trying to check from Unity if several names of a file exists in mysql db.

I add several names with to query the same field name in the db, but only 1 gets picked up. How can I send to php file several names of the same field to be queried in mysql db?

Thanks a bunch for your help

This is my UnityWebRequest:

WWWForm form = new WWWForm();
        foreach (var name in existingDeviceImgNames)
        {
            form.AddField("nameArray", name);
            Debug.Log("Added to form:" + name);
        }

        using (UnityWebRequest www = UnityWebRequest.Post("https://example.com/CompareDeviceNamesVersusDB.php", form))
        {
            yield return www.SendWebRequest();

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log("Form upload complete!");

                string queryResult = www.downloadHandler.text;
                Debug.Log(queryResult);
                if (queryResult.Equals("No records found."))
                    Debug.Log("No entries found");
            }
        }

And this is the php to check the array of names in the db I’ve sent to server:

$namesOnDevice=$_POST["nameArray"];
echo "before - name passed " . count($_POST["nameArray"]);

$setTrue=1;

if(count($_POST["nameArray"])==0)
{
  echo "No records. Exiting.";
  exit;
}

if(count($_POST["nameArray"])==1)
{
  echo "Only 1 record to update in DB: " . $item;

  $updateExists = "UPDATE thisTable SET imgExists='$setTrue' WHERE name='$namesOnDevice'";

  if ($conn->query($updateExists))
      echo "Record updated successfully";
  else
      echo "Error updating record: " . $conn->error;
}

if(count($_POST["nameArray"])>1)
{
  foreach ($namesOnDevice as $item)
  {
    echo "name passed " . $item;

      $updateExists = "UPDATE thisTable SET imgExists='$setTrue' WHERE name='$item'";
 
        if ($conn->query($updateExists))
          echo "Record updated successfully";
        else
          echo "Error updating record: " . $conn->error;
  }
}

SQL injection bugs in your PHP code!!!

Do you have restrictions on your names? You could separate names using comma, then parse them accordingly in php.

Thank you @Aurimas-Cernius , hadn’t thought about passing them this way! And yes, I’m refactoring to pdo :slight_smile: