You are here: Re: PHP forms completely blank « All PHP « IT news, forums, messages
Re: PHP forms completely blank

Posted by Vince Morgan on 02/01/08 15:09

"Jezza" <jezza@s_p_a_m.jonoo.demon.co.uk> 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 <html>,
> <body> 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:
>
>
> <html><head><title>Combined Feedback Form</title></head>
> <body>
> <?php #assign form values when applicable
>
>
>
> $username = $_POST['username'];
> $useraddr = $_POST['useraddr'];
> $comments = $_POST['comments'];
> $sent = $_POST['sent'];
>
>
> #the HTML form that can be written dynamically
>
> $form ="<form action=\"$_SERVER[`PHP_SELF`]\" method=\"post\">";
> $form.="Name:<input type=\"text\" name=\"username\"";
> $form.=" size=\"30\" value=\"$username\" > <br> <br>";
> $form.="Email:<input type=\"text\" name=\"useraddr\"";
> $form.=" size=\"30\" value=\"$useraddr\"> <br> <br>";
> $form.="Comments:<textarea name=\"comments\" ";
> $form.="cols=\"30\" rows=\"5\">$comments</textarea>";
> $form.="<br> <input type=\"submit\" name=\"sent\" ";
> $form. = "value=\"Send Form\"></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:<br>"; $valid = false; }
>
> #check email useraddr field is not blank
> if ( !$useraddr )
> { $errmsg. =" Enter email address : <br>" ; $valid=false; }
> #check comments field is not blank
> if ( !$comments )
> { $errmsg. = "Enter your comments : <br>" ; $valid=false; }
> }
>
> if( !$useraddr )
> { $errmsg .="Enter email address:<br>"; $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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация