PHP forms completely blank

PHP forms completely blank

am 01.02.2008 15:31:42 von Jezza

Hi

I wonder if anyone can help me out. I am a newby and have bought "PHP5
in easy steps" to work through. One project is to have an email form and
responder built into one page. The form simply asks for a username,
email address and comment. It validates to make sure all fields are
filled in, checks the integrity of the email address and then posts it
off.

I have copied the code from the book exactly & even checked & re-checked
the code. Desperately I even scanned the code in via OCR in case I
missed something. When I run the php script the resulting web page is
blank. Looking at the HTML page source, that is also blank (no ,
etc. tags). I suspect the code to be sound and that this problem
is more to do with something within the php.ini file.

I do have PHP files that run fine

I am running Apache 2.2 server with PHP version 4.3.2 & here is the code:


Combined Feedback Form




$username = $_POST['username'];
$useraddr = $_POST['useraddr'];
$comments = $_POST['comments'];
$sent = $_POST['sent'];


#the HTML form that can be written dynamically

$form ="

";
$form.="Name: $form.=" size=\"30\" value=\"$username\" >

";
$form.="Email: $form.=" size=\"30\" value=\"$useraddr\">

";
$form.="Comments:";
$form.="
$form. = "value=\"Send Form\">
" ;


#execute this code if the form has been submitted once
if($sent)
{ $valid=true;
#set variable default value

#check username field is not blank
if( !$username )
{ $errmsg.="Enter your name:
"; $valid = false; }

#check email useraddr field is not blank
if ( !$useraddr )
{ $errmsg. =" Enter email address :
" ; $valid=false; }
#check comments field is not blank
if ( !$comments )
{ $errmsg. = "Enter your comments :
" ; $valid=false; }
}

if( !$useraddr )
{ $errmsg .="Enter email address:
"; $valid = false; }
else ;
{
$useraddr = trim( $useraddr );
#patterns for name,domain and top-level domains
$_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_'{|}-]+";
$_host = " ( [-0-9A-Z]+\.)+";
$_tlds = "([0-9A-Z]){2,4}$/i";
#check validity of email format
if( !preg_match($_name."@".$_host.$_tlds,$useraddr) )
{
$errmsg .= "Email address has incorrect format!
"; $valid = false; }
}

#if invalid write the error message/s and the form

if ( $valid != true )
{ echo ( $errmsg . $form ) ; }

else #if the form is valid send the email

{ $to = "jo@test.co.uk";
$re = "Feedback from $username" ;
$msg = $comments;
$headers = "From: $useraddr \r\n" ;
if ( mail ( $to, $re, $msg, $headers ) )
{ echo ("Thanks for your comments, $username" ) ; }
}
?>



---

Many thanks

Regards

Jeremy

Re: PHP forms completely blank

am 01.02.2008 16:09:50 von Vince Morgan

"Jezza" wrote in message
news:fnvaf7$knd$1$830fa17d@news.demon.co.uk...
> Hi
>
> I wonder if anyone can help me out. I am a newby and have bought "PHP5
> in easy steps" to work through. One project is to have an email form and
> responder built into one page. The form simply asks for a username,
> email address and comment. It validates to make sure all fields are
> filled in, checks the integrity of the email address and then posts it
> off.
>
> I have copied the code from the book exactly & even checked & re-checked
> the code. Desperately I even scanned the code in via OCR in case I
> missed something. When I run the php script the resulting web page is
> blank. Looking at the HTML page source, that is also blank (no ,
> etc. tags). I suspect the code to be sound and that this problem
> is more to do with something within the php.ini file.
>
> I do have PHP files that run fine
>
> I am running Apache 2.2 server with PHP version 4.3.2 & here is the code:
>
>
> Combined Feedback Form
>
> >
>
>
> $username = $_POST['username'];
> $useraddr = $_POST['useraddr'];
> $comments = $_POST['comments'];
> $sent = $_POST['sent'];
>
>
> #the HTML form that can be written dynamically
>
> $form ="

";
> $form.="Name: > $form.=" size=\"30\" value=\"$username\" >

";
> $form.="Email: > $form.=" size=\"30\" value=\"$useraddr\">

";
> $form.="Comments:";
> $form.="
> $form. = "value=\"Send Form\">
" ;
>
>
> #execute this code if the form has been submitted once
> if($sent)
> { $valid=true;
> #set variable default value
>
> #check username field is not blank
> if( !$username )
> { $errmsg.="Enter your name:
"; $valid = false; }
>
> #check email useraddr field is not blank
> if ( !$useraddr )
> { $errmsg. =" Enter email address :
" ; $valid=false; }
> #check comments field is not blank
> if ( !$comments )
> { $errmsg. = "Enter your comments :
" ; $valid=false; }
> }
>
> if( !$useraddr )
> { $errmsg .="Enter email address:
"; $valid = false; }
> else ;

The above "else;" will cause you some grief and is certaily an error. The
shouldn't be a semicolon after else there.
May not be the only mistake either, but I haven't looked much further.
I also think that "if ( !$comments )" should be;
if(!empty($comments)) but it's past my bed time and I haven't given ie much
thought.
HTH
Vince

Re: PHP forms completely blank

am 01.02.2008 16:13:04 von Vince Morgan

"Vince Morgan" wrote in message
news:47a3368d$0$13959$afc38c87@news.optusnet.com.au...
>
> "Jezza" wrote in message
> news:fnvaf7$knd$1$830fa17d@news.demon.co.uk...
I would be looking for another book too.

Re: PHP forms completely blank

am 01.02.2008 16:46:49 von Jerry Stuckle

Jezza wrote:
> Hi
>
> I wonder if anyone can help me out. I am a newby and have bought "PHP5
> in easy steps" to work through. One project is to have an email form and
> responder built into one page. The form simply asks for a username,
> email address and comment. It validates to make sure all fields are
> filled in, checks the integrity of the email address and then posts it off.
>
> I have copied the code from the book exactly & even checked & re-checked
> the code. Desperately I even scanned the code in via OCR in case I
> missed something. When I run the php script the resulting web page is
> blank. Looking at the HTML page source, that is also blank (no ,
> etc. tags). I suspect the code to be sound and that this problem
> is more to do with something within the php.ini file.
>
> I do have PHP files that run fine
>
> I am running Apache 2.2 server with PHP version 4.3.2 & here is the code:
>
>
> Combined Feedback Form
>
> >
>
>
> $username = $_POST['username'];
> $useraddr = $_POST['useraddr'];
> $comments = $_POST['comments'];
> $sent = $_POST['sent'];
>
>
> #the HTML form that can be written dynamically
>
> $form ="

";
> $form.="Name: > $form.=" size=\"30\" value=\"$username\" >

";
> $form.="Email: > $form.=" size=\"30\" value=\"$useraddr\">

";
> $form.="Comments:";
> $form.="
> $form. = "value=\"Send Form\">
" ;
>
>
> #execute this code if the form has been submitted once
> if($sent)
> { $valid=true;
> #set variable default value
>
> #check username field is not blank
> if( !$username )
> { $errmsg.="Enter your name:
"; $valid = false; }
>
> #check email useraddr field is not blank
> if ( !$useraddr )
> { $errmsg. =" Enter email address :
" ; $valid=false; }
> #check comments field is not blank
> if ( !$comments )
> { $errmsg. = "Enter your comments :
" ; $valid=false; }
> }
>
> if( !$useraddr )
> { $errmsg .="Enter email address:
"; $valid = false; }
> else ;
> {
> $useraddr = trim( $useraddr );
> #patterns for name,domain and top-level domains
> $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_'{|}-]+";
> $_host = " ( [-0-9A-Z]+\.)+";
> $_tlds = "([0-9A-Z]){2,4}$/i";
> #check validity of email format
> if( !preg_match($_name."@".$_host.$_tlds,$useraddr) )
> {
> $errmsg .= "Email address has incorrect format!
"; $valid = false; }
> }
>
> #if invalid write the error message/s and the form
>
> if ( $valid != true )
> { echo ( $errmsg . $form ) ; }
>
> else #if the form is valid send the email
>
> { $to = "jo@test.co.uk";
> $re = "Feedback from $username" ;
> $msg = $comments;
> $headers = "From: $useraddr \r\n" ;
> if ( mail ( $to, $re, $msg, $headers ) )
> { echo ("Thanks for your comments, $username" ) ; }
> }
> ?>
>
>
>
> ---
>
> Many thanks
>
> Regards
>
> Jeremy
>

Jeremy,

I didn't check all of your code, but to start, your line:

$form ="
";

uses back tickeys (`) instead of single quotes ('). Hard to see, I know.

Any time you get a blank page (including display source), suspect a
syntax error.

When developing, you should enable all errors and display them. In your
php.ini file, this would be lines:

error_reporting = E_ALL
display_errors = On

Note you shouldn't have display_errors=on in your production system, but
you really need it for production.

One other thing - the line:

else ;

isn't an error in itself - it just terminates else processing and the
code following it (in the braces) will execute all the time. Not what
you want, I'm sure. But it's not an error.

And BTW = PHP 4.3.2 is way old and past end of lifetime. You really
should upgrade to PHP 5.x, especially if you are learning from a PHP 5 book.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: PHP forms completely blank

am 01.02.2008 22:22:25 von Animesh Kumar

Jerry Stuckle wrote:
> Jezza wrote:
>> Hi
>>
>> I wonder if anyone can help me out. I am a newby and have bought "PHP5
>> in easy steps" to work through. One project is to have an email form
>> and responder built into one page. The form simply asks for a
>> username, email address and comment. It validates to make sure all
>> fields are filled in, checks the integrity of the email address and
>> then posts it off.
>>
>> I have copied the code from the book exactly & even checked &
>> re-checked the code. Desperately I even scanned the code in via OCR in
>> case I missed something. When I run the php script the resulting web
>> page is blank. Looking at the HTML page source, that is also blank (no
>> , etc. tags). I suspect the code to be sound and that
>> this problem is more to do with something within the php.ini file.
>>
>> I do have PHP files that run fine
>>
>> I am running Apache 2.2 server with PHP version 4.3.2 & here is the code:
>>
>>
>> Combined Feedback Form
>> >>
>>
>>
>> $username = $_POST['username'];
>> $useraddr = $_POST['useraddr'];
>> $comments = $_POST['comments'];
>> $sent = $_POST['sent'];
>>
>>
>> #the HTML form that can be written dynamically
>>
>> $form ="";
>> $form.="Name: >> $form.=" size=\"30\" value=\"$username\" >

";
>> $form.="Email: >> $form.=" size=\"30\" value=\"$useraddr\">

";
>> $form.="Comments:";
>> $form.="
>> $form. = "value=\"Send Form\">" ;
>>
>>
>> #execute this code if the form has been submitted once
>> if($sent)
>> { $valid=true; #set variable default value
>>
>> #check username field is not blank
>> if( !$username )
>> { $errmsg.="Enter your name:
"; $valid = false; }
>>
>> #check email useraddr field is not blank
>> if ( !$useraddr )
>> { $errmsg. =" Enter email address :
" ; $valid=false; }
>> #check comments field is not blank
>> if ( !$comments )
>> { $errmsg. = "Enter your comments :
" ; $valid=false; }
>> }
>>
>> if( !$useraddr )
>> { $errmsg .="Enter email address:
"; $valid = false; }
>> else ;
>> {
>> $useraddr = trim( $useraddr );
>> #patterns for name,domain and top-level domains
>> $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_'{|}-]+";
>> $_host = " ( [-0-9A-Z]+\.)+";
>> $_tlds = "([0-9A-Z]){2,4}$/i";
>> #check validity of email format
>> if( !preg_match($_name."@".$_host.$_tlds,$useraddr) )
>> {
>> $errmsg .= "Email address has incorrect format!
"; $valid = false; }
>> }
>>
>> #if invalid write the error message/s and the form
>>
>> if ( $valid != true )
>> { echo ( $errmsg . $form ) ; }
>>
>> else #if the form is valid send the email
>>
>> { $to = "jo@test.co.uk";
>> $re = "Feedback from $username" ;
>> $msg = $comments;
>> $headers = "From: $useraddr \r\n" ;
>> if ( mail ( $to, $re, $msg, $headers ) )
>> { echo ("Thanks for your comments, $username" ) ; }
>> }
>> ?>
>>
>>
>>
>> ---
>>
>> Many thanks
>>
>> Regards
>>
>> Jeremy
>>
>
> Jeremy,
>
> I didn't check all of your code, but to start, your line:
>
> $form ="

";
>
> uses back tickeys (`) instead of single quotes ('). Hard to see, I know.
>

I use single quotes and it works fine on a Linux hosting service with
Php5.0

Re: PHP forms completely blank

am 01.02.2008 23:34:38 von Jerry Stuckle

Animesh K wrote:
> Jerry Stuckle wrote:
>> Jezza wrote:
>>> Hi
>>>
>>> I wonder if anyone can help me out. I am a newby and have bought
>>> "PHP5 in easy steps" to work through. One project is to have an email
>>> form and responder built into one page. The form simply asks for a
>>> username, email address and comment. It validates to make sure all
>>> fields are filled in, checks the integrity of the email address and
>>> then posts it off.
>>>
>>> I have copied the code from the book exactly & even checked &
>>> re-checked the code. Desperately I even scanned the code in via OCR
>>> in case I missed something. When I run the php script the resulting
>>> web page is blank. Looking at the HTML page source, that is also
>>> blank (no , etc. tags). I suspect the code to be sound
>>> and that this problem is more to do with something within the php.ini
>>> file.
>>>
>>> I do have PHP files that run fine
>>>
>>> I am running Apache 2.2 server with PHP version 4.3.2 & here is the
>>> code:
>>>
>>>
>>> Combined Feedback Form
>>> >>>
>>>
>>>
>>> $username = $_POST['username'];
>>> $useraddr = $_POST['useraddr'];
>>> $comments = $_POST['comments'];
>>> $sent = $_POST['sent'];
>>>
>>>
>>> #the HTML form that can be written dynamically
>>>
>>> $form ="";
>>> $form.="Name: >>> $form.=" size=\"30\" value=\"$username\" >

";
>>> $form.="Email: >>> $form.=" size=\"30\" value=\"$useraddr\">

";
>>> $form.="Comments:";
>>> $form.="
>>> $form. = "value=\"Send Form\">" ;
>>>
>>>
>>> #execute this code if the form has been submitted once
>>> if($sent)
>>> { $valid=true; #set variable default value
>>>
>>> #check username field is not blank
>>> if( !$username )
>>> { $errmsg.="Enter your name:
"; $valid = false; }
>>>
>>> #check email useraddr field is not blank
>>> if ( !$useraddr )
>>> { $errmsg. =" Enter email address :
" ; $valid=false; }
>>> #check comments field is not blank
>>> if ( !$comments )
>>> { $errmsg. = "Enter your comments :
" ; $valid=false; }
>>> }
>>>
>>> if( !$useraddr )
>>> { $errmsg .="Enter email address:
"; $valid = false; }
>>> else ;
>>> {
>>> $useraddr = trim( $useraddr );
>>> #patterns for name,domain and top-level domains
>>> $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_'{|}-]+";
>>> $_host = " ( [-0-9A-Z]+\.)+";
>>> $_tlds = "([0-9A-Z]){2,4}$/i";
>>> #check validity of email format
>>> if( !preg_match($_name."@".$_host.$_tlds,$useraddr) )
>>> {
>>> $errmsg .= "Email address has incorrect format!
"; $valid = false; }
>>> }
>>>
>>> #if invalid write the error message/s and the form
>>>
>>> if ( $valid != true )
>>> { echo ( $errmsg . $form ) ; }
>>>
>>> else #if the form is valid send the email
>>>
>>> { $to = "jo@test.co.uk";
>>> $re = "Feedback from $username" ;
>>> $msg = $comments;
>>> $headers = "From: $useraddr \r\n" ;
>>> if ( mail ( $to, $re, $msg, $headers ) )
>>> { echo ("Thanks for your comments, $username" ) ; }
>>> }
>>> ?>
>>>
>>>
>>>
>>> ---
>>>
>>> Many thanks
>>>
>>> Regards
>>>
>>> Jeremy
>>>
>>
>> Jeremy,
>>
>> I didn't check all of your code, but to start, your line:
>>
>> $form ="

";
>>
>> uses back tickeys (`) instead of single quotes ('). Hard to see, I know.
>>
>
> I use single quotes and it works fine on a Linux hosting service with
> Php5.0
>

Yes, that's the way you should do it. he didn't. Read my message again.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================