tags:

views:

52

answers:

3

Hi,

My site is working fine on my localhost. But, when I upload the latest stuff to the server, I get the following error:

[13-Sep-2010 20:40:22] PHP Notice:  Undefined variable: query in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 143
[13-Sep-2010 20:40:22] PHP Warning:  mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 146
[13-Sep-2010 20:40:22] PHP Warning:  mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 156
[13-Sep-2010 20:40:29] PHP Notice:  Undefined variable: query in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 143
[13-Sep-2010 20:40:29] PHP Warning:  mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 146
[13-Sep-2010 20:40:29] PHP Warning:  mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 156

Code Below:

Below is what I put on the server. It throws the above error. It's not too pretty, but it works locally. The only difference between the localhost version and the server version is the path for the first require once. I've got the correct path as it's the same for all of my other php classes.

<?php
require_once('/home/mysite/connection/connection_mysite.php');
require_once('VOscore1.php');


class MyScoreData {

public function getScoreData($schoolPollSelections) {

        $schoolYear = $schoolPollSelections[0];
        $schoolType = $schoolPollSelections[1];
        $schoolGradeLevel= $schoolPollSelections[2];
        $schoolSubject = $schoolPollSelections[3];
        $myTable = 'mc_school_report_card_sy_'.$schoolYear;
        $myTable2 = 'mc_school_scores_sy_'.$schoolYear;


        if($schoolYear == '2009_2010') {

            if($schoolType == 'both'){
                if($schoolSubject == 'M'){$query = "SELECT DISTINCT school_name_sy09_10 AS school, ROUND(math_below_basic) AS percent_below_basic, ROUND(math_basic) AS percent_basic, ROUND(math_proficient) AS percent_proficient, ROUND(math_advanced) AS percent_advanced, ROUND(math_proficient + math_advanced) AS percent_proficient_and_advanced  FROM mc_school_scores_latlong WHERE category='$schoolGradeLevel' AND lea!='n' AND year='2010' AND status_sy09_10!='closed' AND status_sy09_10!='unknown' AND math_below_basic IS NOT NULL  AND grade_school_type_sy09_10!='Special Education School' ORDER BY percent_proficient_and_advanced DESC";}

        if($schoolSubject == 'R'){$query = "SELECT DISTINCT school_name_sy09_10 AS school, ROUND(reading_below_basic) AS percent_below_basic, ROUND(reading_basic) AS percent_basic, ROUND(reading_proficient) AS percent_proficient, ROUND(reading_advanced) AS percent_advanced, ROUND(reading_proficient + reading_advanced) AS percent_proficient_and_advanced  FROM mc_school_scores_latlong WHERE category='$schoolGradeLevel' AND lea!='n' AND year='2010' AND status_sy09_10!='closed' AND status_sy09_10!='unknown' AND reading_below_basic IS NOT NULL AND grade_school_type_sy09_10!='Special Education School' ORDER BY percent_proficient_and_advanced DESC";} 
            }

            else{

            if($schoolSubject == 'M'){$query = "SELECT DISTINCT school_name_sy09_10 AS school, ROUND(math_below_basic) AS percent_below_basic, ROUND(math_basic) AS percent_basic, ROUND(math_proficient) AS percent_proficient, ROUND(math_advanced) AS percent_advanced, ROUND(math_proficient + math_advanced) AS percent_proficient_and_advanced  FROM mc_school_scores_latlong WHERE category='$schoolGradeLevel' AND lea='$schoolType' AND lea!='n' AND year='2010' AND status_sy09_10!='closed' AND status_sy09_10!='unknown' AND math_below_basic IS NOT NULL  AND grade_school_type_sy09_10!='Special Education School' ORDER BY percent_proficient_and_advanced DESC";}

        if($schoolSubject == 'R'){$query = "SELECT DISTINCT school_name_sy09_10 AS school, ROUND(reading_below_basic) AS percent_below_basic, ROUND(reading_basic) AS percent_basic, ROUND(reading_proficient) AS percent_proficient, ROUND(reading_advanced) AS percent_advanced, ROUND(reading_proficient + reading_advanced) AS percent_proficient_and_advanced  FROM mc_school_scores_latlong WHERE category='$schoolGradeLevel' AND lea='$schoolType' AND lea!='n' AND year='2010' AND status_sy09_10!='closed' AND status_sy09_10!='unknown'  AND reading_below_basic IS NOT NULL AND grade_school_type_sy09_10!='Special Education School' ORDER BY percent_proficient_and_advanced DESC";}  
            }
        }



        if($schoolYear == '2008_2009') {

            if($schoolType == 'both'){
                if($schoolSubject == 'M'){$query = "SELECT DISTINCT school, ROUND(math_below_basic) AS percent_below_basic, ROUND(math_basic) AS percent_basic, ROUND(math_proficient) AS percent_proficient, ROUND(math_advanced) AS percent_advanced, ROUND(math_proficient + math_advanced) AS percent_proficient_and_advanced  FROM $myTable2 WHERE category='$schoolGradeLevel' AND lea!='n' ORDER BY percent_proficient_and_advanced DESC";}

        if($schoolSubject == 'R'){$query = "SELECT DISTINCT school, ROUND(reading_below_basic) AS percent_below_basic, ROUND(reading_basic) AS percent_basic, ROUND(reading_proficient) AS percent_proficient, ROUND(reading_advanced) AS percent_advanced, ROUND(reading_proficient + reading_advanced) AS percent_proficient_and_advanced  FROM $myTable2 WHERE category='$schoolGradeLevel' AND lea!='n' ORDER BY percent_proficient_and_advanced DESC";}    
            }

            else{

            if($schoolSubject == 'M'){$query = "SELECT DISTINCT school, ROUND(math_below_basic) AS percent_below_basic, ROUND(math_basic) AS percent_basic, ROUND(math_proficient) AS percent_proficient, ROUND(math_advanced) AS percent_advanced, ROUND(math_proficient + math_advanced) AS percent_proficient_and_advanced  FROM $myTable2 WHERE category='$schoolGradeLevel' AND lea='$schoolType' AND lea!='n' ORDER BY percent_proficient_and_advanced DESC";}

        if($schoolSubject == 'R'){$query = "SELECT DISTINCT school, ROUND(reading_below_basic) AS percent_below_basic, ROUND(reading_basic) AS percent_basic, ROUND(reading_proficient) AS percent_proficient, ROUND(reading_advanced) AS percent_advanced, ROUND(reading_proficient + reading_advanced) AS percent_proficient_and_advanced  FROM $myTable2 WHERE category='$schoolGradeLevel' AND lea='$schoolType' AND lea!='n' ORDER BY percent_proficient_and_advanced DESC";}  
            }
        }


        if(($schoolYear != '2008_2009') && ($schoolYear != '2009_2010') ) {

        if(($schoolType == 'D') || ($schoolType == 'P')) {$query = "SELECT DISTINCT school, ROUND(percent_below_basic) AS percent_below_basic, ROUND(percent_basic) AS percent_basic, ROUND(percent_proficient) AS percent_proficient, ROUND(percent_advanced) AS percent_advanced, ROUND(percent_proficient + percent_advanced) AS percent_proficient_and_advanced  FROM  $myTable WHERE  subgroup='Total' AND subject='$schoolSubject' AND category='$schoolGradeLevel' AND school_code NOT LIKE 'L%' AND school_code!='STATE' AND school!='BOE CHARTER' AND school!='TUITION GRANTS' AND lea='$schoolType' AND school!='LEA' AND school!='DCPS SCHOOLS' AND school!='PUBLIC CHARTER' ORDER BY percent_proficient_and_advanced DESC";}

        //if both is chosen as schooltype then it runs query below
        else {$query = "SELECT DISTINCT school,  ROUND(percent_below_basic) AS percent_below_basic, ROUND(percent_basic) AS percent_basic, ROUND(percent_proficient) AS percent_proficient, ROUND(percent_advanced) AS percent_advanced, ROUND(percent_proficient + percent_advanced) AS percent_proficient_and_advanced FROM  $myTable WHERE  subgroup='Total' AND subject='$schoolSubject'  AND category='$schoolGradeLevel' AND school_code NOT LIKE 'L%' AND school_code!='STATE' AND school!='BOE CHARTER' AND school!='TUITION GRANTS' AND school!='LEA' AND school!='DCPS SCHOOLS' AND school!='PUBLIC CHARTER' ORDER BY percent_proficient_and_advanced DESC";}

        }



         $mysql = mysql_connect(DATABASE_SERVER12, DATABASE_USERNAME12, DATABASE_PASSWORD12);
         mysql_select_db(DATABASE_NAME12);



            $result = mysql_query($query);

            $ret = array();
                 while ($row = mysql_fetch_object($result)) {
                    $tmp = new VOscore1();
                    $tmp->school = $row->school;
                    $tmp->percent_below_basic = $row->percent_below_basic;
                    $tmp->percent_basic = $row->percent_basic;
                    $tmp->percent_proficient = $row->percent_proficient;
                    $tmp->percent_advanced = $row->percent_advanced;
                    $tmp->percent_proficient_and_advanced = $row->percent_proficient_and_advanced;
                    $ret[] = $tmp; 
                        }
                 mysql_free_result($result);

                 return $ret;


    }       



}
?>

Any ideas as to why it's not working on the server, but works locally? What should I do?

Thanks.

-Laxmidi

+1  A: 

If you are including or requiring files or the query variable comes from another file, ensure that all your paths to files and libraries are correct on the server, they are probably different to the paths on your local development environment.

Could you please also post the code?

Stoosh
Hi Stoosh, Thank you for trying to help me out. I've posted the class. It's kind of an ugly ball of spaghetti, but it works locally. If you have any suggestions, please let me know. I'll re-check the paths (again).
Laxmidi
A: 

Most likely what's occurring is that NONE of the options you're checking for in that ball of if() statements matches, so $query is never defined, and when the code reaches the mysql_query() line, it's trying to run a NULL query, basically $result = mysql_query('');

I suspect that if you changed the actual query call line to this:

$result = mysql_query($query) or die("MySQL error: " . mysql_error());

you'd see the script abort at that point with a 'null query' error message. As it stands now, the function call is most likely returning FALSE to indicate an error occured, and then you try to use that FALSE value in the mysql_fetch_assoc(), which produces the ... not a valid MySQL result resource errors.

To fix, put a default query before all the if() statements, so that if none of the options match, you still have some kind of valid query. Or, if you don't want to run a query at that point, you can surround the query/fetch block in an if:

 if (!empty($query)) {
      $result = mysql_query(...)
      // etc...
      return($ret);
 } else {
      return($some_default_value_to_signify_nothing_was_done);
 }
Marc B
A: 

Okay, I figured it out. I used an Alert in the release build to trace a Flex variable that sets $schoolPollSelections. It showed that the variable was not being set by my radioButton and list control. This variable was an array of parameters used by MyScoreData. And therefore, MyScoreData couldn't grab the data.

The weird thing was that the variable was shown as having all of the parameters when I traced it on the localhost. But, it wasn't set, when it was on the remote server. I don't know why. In any event, I got the variable properly set on both hosts and it works.

Thank you to Stoosh, Marc B, and Andrew Heath for your kind help.

Laxmidi