Query returning blank page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Query returning blank page

Post by divito »

Been having issues all night with a bunch of my code and files and am getting really angry, but this one is one I'm most confused about.

It returns a blank page. Turning on error reporting for PHP and for MySQL shows nothing unless I purposefully make something wrong, but leaving it as is just gives me a blank page. What gives?

Code: Select all

<?
 
include ("db_connection");
 
$query = "SELECT * FROM Events";
$result = MYSQL_QUERY($query) or die('Query Failed');
 
while ($list = mysql_fetch_assoc($result)) {
   
    $start = $list['Start'];
    $end = $list['End'];
    $name = $list['Name'];
    $location = $list['Location'];
    $venue = $list['Venue'];
    $money = $list['Money'];
    $games = $list['Games'];
    
    $date_array = explode("-",$start);
    $date_array2 = explode("-",$end);
        
    $year = $date_array[0];
    $month = $date_array[1];
    $day = $date_array[2];
    $end = $date_array2[2];
    $month2 = $date_array2[1];
    
    if ($month != $month2) {
    
    echo "Event Name: ".$name."<br>";
    Month($month);echo " ".$day."-"; Month($month2); echo " ".$end.", ".$year;
    echo "Location: ".$location."<br>";
    echo "Venue: ".$venue."<br>";
    echo "Total Prize Money: ".$money."<br>";
    echo "Games: ".$games."<br>";
    } else {
    
    echo "Event Name: ".$name."<br>";
    Month($month);echo " ".$day."-".$end.", ".$year;
    echo "Location: ".$location."<br>";
    echo "Venue: ".$venue."<br>";
    echo "Total Prize Money: ".$money."<br>";
    echo "Games: ".$games."<br>";
    
    }
    }
?>
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: Query returning blank page

Post by ldougherty »

This line is throwing an error when I try and replicate the code on my server

Code: Select all

Month($month);echo " ".$day."-"; Month($month2); echo " ".$end.", ".$year;
it says

Fatal error: Call to undefined function Month() in /var/www/vhosts/ldollar.com/httpdocs/test.php on line 38

Use this instead

Code: Select all

echo "Month($month)";echo " ".$day."-".$end.", ".$year;
That should work.
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: Query returning blank page

Post by divito »

I have my function setup just above my db connection include (it has a return so it doesn't need an echo).
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Query returning blank page

Post by califdon »

divito wrote:I have my function setup just above my db connection include (it has a return so it doesn't need an echo).
Huh? Are you under the mistaken impression that because a function returns a value, it doesn't need to be echoed?????
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: Query returning blank page

Post by divito »

Perhaps not in all cases, but when I originally made the function and tried to echo it, it didn't work. When I removed the echo, it did. :|
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: Query returning blank page

Post by ldougherty »

a good method to determine if the page is failing to load at all ie PHP error or if your results just aren't coming back as expected..

create a title tag in the head and give it a value. If the page parses then your title will show, if you have a PHP error you will not even see the title.
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: Query returning blank page

Post by divito »

Title shows, still blank page. :banghead:
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: Query returning blank page

Post by ldougherty »

OK, that means your query is running since your not getting the DIE message but no results.

Try echoing out random text in different places such as before the while loop, in the while loop, and after the while loop to see what works and what doesn't.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Query returning blank page

Post by Benjamin »

How about turning on error reporting so you don't have to "guess" at what the issue is. Put this at the top of your code and post the results please.

Code: Select all

 
error_reporting(E_ALL);
ini_set("display_errors", 1);
 
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Query returning blank page

Post by jaoudestudios »

astions wrote:How about turning on error reporting so you don't have to "guess" at what the issue is. Put this at the top of your code and post the results please.

Code: Select all

 
error_reporting(E_ALL);
ini_set("display_errors", 1);
 
Good idea.

Always develop with full error reporting on!
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: Query returning blank page

Post by divito »

divito wrote:Been having issues all night with a bunch of my code and files and am getting really angry, but this one is one I'm most confused about.

It returns a blank page. Turning on error reporting for PHP and for MySQL shows nothing unless I purposefully make something wrong, but leaving it as is just gives me a blank page. What gives?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Query returning blank page

Post by jaoudestudios »

this probably wont fix it, but use the full php tags and all functions should be in lower case (i.e. MYSQL_QUERY)
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: Query returning blank page

Post by divito »

I have full tags in the actual file, I just used the short one when I pasted some the code here. My site has no issue with short tags though. And I changed the function to lower case as requested; was just like that from an old tutorial so I always just copied it over.

As you guessed, didn't fix it though.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Query returning blank page

Post by Benjamin »

There are two possible issues. 1. Your script has a fatal error. 2. The query isn't returning any records.
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: Query returning blank page

Post by divito »

I managed to fix it. I moved the include for the db connection after the function and it magically started working. Anyone have an explanation for that one?
Post Reply