views:

26

answers:

2

I am learning PHP and I am at this point learning how to validate forms and client inputs.

Clearly I have misspelled, written something not related to PHP or anything like that, because I get nothing but a white screen, but I just can't find out where the error is generated.

A weird thing is, that even though I have turned on error reporting and displaying of errors all I get is a so-called WSOD (White Screen of Death)

This is the PHP-code:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
if (array_key_exists('_submit_check', $_POST))  {
if (validate_form()) {
    process_form();
} else {
    show_form();
}
} else {
show_form();
}

function process_form() {
print "Hello, " . $_POST['my_name'];
}

function show_form() {
print<<<HTML
<form method="POST" action="$_SERVER[PHP_SELF]">
Your name: <input type="text" name="my_name">
<br>
<input type="submit" value="Say HEEELLOOO!">
<input type="hidden" name="_submit_check" value="1">
</form>
HTML;
}

function validate_form() {
if (strlen($_POST['my_name'] < 3) {
    return false;
} else {
    return true;
}
}
?>

Please no "Why are you doing this server-side? Bla bla bla", it's just an "excercise"

If you can spot where I made the error, please let me know and if you can tell me why i get nothing but a white screen when I make a mistake please let me know too! :) Thanks

+2  A: 

Just a thought - have you checked via php_info(); that error reporting is turned on, that fatal errors, etc. aren't being repressed and that errors aren't being sent to a file?

(Yes, I know you said that it's turned on, and that you're attempting to update error reporting, etc. at the start of the script, but I'm just checking that it's picking up the changes.) :-)

In essence, if error reporting was really turned on, you'd see an error.

middaparka
I see what you mean... Give me a minute, I will make sure it's turned on.
Latze
You where right - the errors are stored in some .log-file. How can I make the errors appear on the screen?
Latze
+2  A: 
if (strlen($_POST['my_name']) < 3) {
Mark Baker
Isn't it if (strlen($_POST['my_name']) < 3) {... ?because strlen() is a function ... So basically it's if (strlen(something) is less than three) { then return false...
Latze
True enough... I identified the missing bracket, but displayed it in the wrong position when I posted the response.... edited to correct
Mark Baker
Thank you a lot :)
Latze