Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chainprayer

macrumors 6502a
Original poster
Feb 10, 2008
638
2
anyone else ever have any problems using php with godaddy? i have a simple php script set up to connect to my sql database. when there is an error in the code it returns a blank page instead of an error with a reference to the error line. anyone else have this happening?
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
If GoDaddy doesn't give you access to the PHP error log file then you can try to catch the errors using try..catch and/or die statements.
 

SrWebDeveloper

macrumors 68000
Dec 7, 2007
1,871
3
Alexandria, VA, USA
A blank page usually means a "fatal" error such as a typo in a function name, missing ; on the end, syntax error as the script is intepreted.

You can trap (PHP4:most, PHP5: almost all) errors with set_error_handler() callback function but be sure to read the exceptions and notes on this page at php.net.
 

DipDog3

macrumors 65816
Sep 20, 2002
1,191
812
A blank page usually means a "fatal" error such as a typo in a function name, missing ; on the end, syntax error as the script is intepreted.

I second this. Check that all lines of codes end with ; and that all comments are probably commented.

When I can't find the problem, I will comment out sections of the code until the PHP file runs, then I can narrow down the problem.
 

IanTheLesser

macrumors newbie
Aug 4, 2010
2
0
checking database access

I can relate -- I've had issues I still don't understand with GoDaddy's php server, and I have some background with php and am using a Linux server, not the Windows flavor.

Here's a few things that can help, though:

(hopefully not restating the obvious) Try queries first from GoDaddy's phpMyAdmin, which you can get to from the Hosting control panel by selecting Databases, clicking on MySQL, and going through the login if you've got your DB's set up. Sometimes this can reveal details missed on the code side, where you're usually dealing with inline SQL.

Make sure that if you use any $_POST or $_GET variables in your query and are using double quotes or heredoc, you enclose them in curly brackets. If they're string values, put the curly brackets inside the quotes that go into the SQL.

Finally, even if you don't have access to the error log file directly, I found out recently that php has nifty functions just to check this kind of thing -- it would work something like this:

Code:
<?php
//assuming connection has already been made and DB selected
$result = mysql_query($query, $connection);
if (!$result) {
$report = 'Query failed for the following reason: <br />';
$report.= mysql_errno($connection). ": ";
$report.= mysql_error($connection);
echo $report
//alternately, if this is a backend process like PayPal IPN,
//you could use mail($recipient, "Query Failed", $report)
}
?>

Hopefully this is helpful.
 

harpster

macrumors regular
Jan 26, 2010
135
7
You might have an error in your SQL statements and often that will not output an error message. You can use the "die" statement combined with "mysql_error" as in the following two examples. Either one with your connect values should output an error if there is one.

PHP:
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>


PHP:
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or die(mysql_error());
echo "Connected to MySQL<br />";
?>


Also to see if display_errors is working for php (not the mysql part) just make an even simpler php file with 2 or 3 lines and test by messing up something. I'm sure you will see an error message generated.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.