unity, forms and php

<?php


    $db = mysql_connect('###, '###', '###'); 
    if (!$db) { 
        die('Could not connect: ' . mysql_error()); 
    } 

    mysql_select_db(nbnmarslab) or die('Could not select database');
    $name = mysql_real_escape_string('School2');
    
    
    $addSchool =  'INSERT INTO `Users` (`SchoolName`, `email`) VALUES (\'test\', \'test@test\');'; 
    mysql_query($addSchool) or die('Query failed: ' . mysql_error());
?>

now this adds a row to my table, but I can’t figure how to change this to accept variable from the wwwform in unity. The escape characters are causing me major headaches I think.

I know this isn’t 100% a unity question, but I am sure others with limited SQL experience are trying to do similar things with unity.

solution

$addSchool =  'INSERT INTO `Users` (`SchoolName`, `email`) VALUES (\''.$name.'\', \''.$email.'test@test\');';

You may already know this, but PHP’s mysql extension is deprecated. You should probably start new projects using alternative extensions such as mysqli or PDO.

Messing around with escape characters is messy (and dangerous!). In the long run, it’s easier and more secure to use prepared statements, so that your data and queries are completely separated.

thanks for the advice. I don’t know much. I was just trying to get some basic communication between a database to and from unity. I have succeeded to do that at least :slight_smile: