PDA

View Full Version : PHP returning 'undefined' from mysql


newsomjk
03-01-2011, 08:20 PM
I can't for the life of me figure out what's going wrong here, and I'm not well versed in mysql so I feel like it's something simple...

here's my php file:


<?php
$connection=mysql_connect("localhost","nt","1013433D7") or die(mysql_error());
mysql_select_db("Doors_Database") or die(mysql_error());

if ($_POST['sendRequest'] == "top5") {

$level=$_POST['currentLevel'];
$myFile="output.txt";
$fh=fopen($myFile,'w');
fwrite($fh,"inside top5 request\n");


$fp="SELECT username FROM hiscores WHERE level=".$level." ORDER BY score ASC LIMIT 1";
fwrite($fh,$fp." request made.\n");
$result=mysql_query($fp);
if($result){
fwrite($fh,"users returned");
}
else{
fwrite($fh,"users not retured");
}

$r1=mysql_fetch_assoc($result);
$rl=$rl['username']



print "var1= $r1";
print "&var2= $r1";
print "&var3= $r1";
print "&var4= $r1";
print "&var5= $r1";
}//END OF REQUEST FOR TOP 5 PLAYERS

mysql_close($connection);
?>
nothing gets printed to a file, and the flash application receives 'undefined' from the php file...

I know the flash code is fine the way it is

mike007
03-02-2011, 03:25 PM
First thing, you need to separate your code into functions that make scene. Have one function for calling the database and returning the value. One for returning the mysql result into something that php can read and one for writting your text file and one for printing results. You have a little bit of everything jumbled in here.

This will help you and me figure out where the problem is in the code.