Jump to content

empty page


mangtas_ka

Recommended Posts

Hello everybody,

 

I am new to php, I have a question for you guys.

why I've got an empty page.

 

<?php
//MySQL database connection
//connect_db.php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="logans1966"; // Mysql password 
$db_name="Inventory"; // Database name
$conn = mysql_connect("$host","$username","$password")  or die(mysql_error());
mysql_select_db("$db_name")or die("cannot select DB");
if ($conn) {
   echo ("Connection is succeed");
} else {
   echo ("Connection is fail");
}
?>
thanks in advance
cris

 

Link to comment
Share on other sites

Do you know if PHP is set to display all errors and warnings? Note that you can add the following to the top of your script to show them:

<?php
//REPORT ALL PHP ERRORS
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
 
 
Side note:
Perhaps you are already aware of this, but the mysql_* functions have been deprecated. At some point in the near future, you'll need to switch to PDO or MySQLi. More information can be found here:
Link to comment
Share on other sites

What you want to do when you develop (meaning on your computer or a test server or whatever) is to display ALL of the messages PHP can send to you so that you can fix them as soon as possible.

 

When your code is 'live' (accessible from the Internet), you want to display a nice custom error page. You certainly don't want to show to your users error messages coming from PHP. It's not secure, it's ugly and it won't help your users anyway. But, you want to be able to see the errors, that's why you should at least log them.

 

To try what's happening on your server (either it's on your production or development server), you can create a single PHP file with only this content:

<?php
foo();

The function 'foo()' shouldn't exist, so when you call that page, you should see an error message. If you see a white page, it's because your PHP error settings tells PHP not to output any error.

 

If you actually want to see the errors, you could change your settings in php.ini to:

display_errors=On
error_reporting=E_ALL
log_errors=1

Or, if you want to (but it's not the cleanest way), you can add this to your code:

 

 

ini_set('display_errors','On');
ini_set('log_errors',1);
ini_set('error_reporting',E_ALL);

 

If you want to know more, I wrote an article about Error settings with PHP. If you read it, I'd love to have your comments! :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.