March 8, 2012

PHP failing to show error messages

Question by Sergei

I wrote some code as a start for a username and password registration page but i cant get the first bit to work. The page with the forms corresponding to the variables at the top work fine but when redirected to this page it just gives a blank white page.

I seem to get this error every time i write some code that is not just basic echo or something like that… Can someone tell me what is wrong with the code and is there any good php editor where you can see error messages or somethilng like that?

This is not the first time i get the same blank page error and i would love to know what i’m doing wrong.

<?php
$user = $_POST["username"];
$pass = $_POST["password"];
$conf_pass = $_POST["conf_password"];

$con = mysql_connect("localhost", "webuser1", "12345");
if (!$con) {
  die('Could not connect: ' . mysql_error());
}

if($pass != $conf_pass) {
  echo ("passwords don't match, <a href="./reg_form.php">return</a>");
}



mysql_close($con);

?>

Answer by MrCode

A blank white page often indicates a 500 Internet Server Error, which usually means you have a syntax or other error in your code.

In your case the error is in the quotes, try changing to:

 echo ("passwords don't match, <a href='./reg_form.php'>return</a>");

I suggest turning on error reporting in your code, or you can check your error log, this will tell you what the problem is and the line number.

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

Also, if using Firebug, you can see the 500 Internal Server Error on the Net tab.

Answer by Starx

There are errors occurring on your code. To see what error is being generated. Use this command on the top of your page.

error_reporting(E_ALL);

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!