Could someone help me debug my PHP?

I’m trying to connect to my database but I am having alot of trouble and I keep getting a 500 error.
NOTE: I took out the database info because I don’t want you guys knowing the code. =P

Gridnum = mysql_real_escape_string(_GET[‘GridNumber’], $dbname);
echo “OLOL {$Gridnum}”
$result = mysql_query(“SELECT * FROM medsouzNATION WHERE GridId=$Gridnum”) or die(mysql_error());
$row = mysql_fetch_array( $result );
echo “UMG {$row[‘Terrain’]}”

Are you sure the error 500 isn’t caused by something wrong in the server itself?
Also, try adding ; after echoes and putting ’ around the $Gridnum in your query.

Thanks, I know it isn’t the server because the other PHP scripts (that I didn’t make but put there) work fine. This is my first attempt at coding in PHP. I’ll try the echos though.

Okay the PHP isn’t broken anymore but when I try and retreive the data through Unity it fails, here is the PHP(once again with database data taken out):

$Gridnum = $_GET['GridNumber'];
$result = mysql_query("SELECT * FROM medsouzNATION WHERE GridId='$Gridnum'") or die(mysql_error());  
$row = mysql_fetch_array( $result );
if ($row){
echo $row['TerType'];
}
else {
echo "No row found...";
}

Here is the simplifiedf Unity3D javascript code:

var num = 1;
var form = new WWWForm(); 
form.AddField( "GridNumber", num); 
var w = WWW(PHP, form);
yield w;
Debug.Log(w.data);

Everytime I try and retreive the data through Unity I get

Comon can someone help? I need to figure this out tonight! :shock:

One big problem is that your PHP script is trying to retrieve GridNumber through GET, but when you use WWWForm, the data is sent via POST.

Wow… :sweat_smile: This has confused me all day, thank you!

Okay I got the same issue again… Here is the updated PHP.

$Gridnum = $_POST['GridNumber'];
$result = mysql_query("SELECT * FROM medsouzNATION WHERE GridId='$Gridnum'") or die(mysql_error());  
$row = mysql_fetch_array( $result );
if ($row){
echo $row['TerType'];
}
else {
echo "No row found...";
}
?>

Okay, so the first thing is it doesn’t seem like we know if the Unity script is causing the problem, or the PHP script.

I suggest doing this:

$Gridnum = $_REQUEST['GridNumber']; 
$result = mysql_query("SELECT * FROM medsouzNATION WHERE GridId='$Gridnum'") or die(mysql_error());  
$row = mysql_fetch_array( $result ); 
if ($row){ 
echo $row['TerType']; 
} 
else { 
echo "No row found..."; 
} 
?>

Then visiting your page with a GET parameter:

http://www.yoursite.com/script.php?GridNumber=1

_REQUEST is _GET and $_POST together, so we can test the PHP script without having Unity make the call to the script.

Visit the URL, and you should get either one of your echoes, and ONLY that text.

When I did it with the $_GET it worked fine in the URL so therefore its a Unity issue.

I found a way around this issue by using another script instead of the large one it was in. I have no clue why it worked this way and not the other way… :?

Oh well this new way is faster (Runs even when you not in the scene so it preloads).

Could you post the fix for others whom might have this issue to see?

Glad you got it resolved though :slight_smile:

Um… I didn’t really do anything except paste the code into a different script that is just for retreiving the PHP. 8)