troubleshooting Question

php embed in html bug

Avatar of ResourcefulDB
ResourcefulDB asked on
PHPHTMLWeb Development
2 Comments1 Solution375 ViewsLast Modified:
Hi all,

I am pretty new to php. Here is one simple program I try to work out how php embed in html. It gives one funny result. In one occasion, I fill in only name and email, but not the message. The first time I click on submit button, it tell me the length of message is 0. Then I click on it one more time, it tell me the length is 2. Every time, we click the button, the lenght increase by 2.

Please help me to understand why it does that.

Thanks,
RDB

 
<?php
if (isset($_POST['name']))
{
 $name = $_POST['name'];  
 $email = $_POST['email'];
 $message = $_POST['message'];
 
 $errorstring = "";
 if (!$name)
 $errorstring = $errorstring."Name<br>";
 if (!$email)
 $errorstring = $errorstring."Email<br>";
 if (!$message)
 $errorstring = $errorstring."Message<br>";
 
 echo "The length of message is ".strlen($message);
 echo "<br>";

 if ($errorstring!="")
 echo "Please fill out the following fields:<br> $errorstring";
 else
 {

 echo "Success!";
 echo "<form action='formvalidation.php' method='POST'>";
 echo "</form>";

 }

}
?>

<form action="formvalidation.php" method='POST'>
Name: <input type='text' name='name' value='<?php echo $name; ?>'> <br>
Email: <input type='text' name='email' > <br>
Message: <textarea name='message' rows='5' cols='40'> <?php echo $message; ?> </textarea> <br>
<input type="submit" name="click" value='Send'> <br>
</form>

Open in new window

ASKER CERTIFIED SOLUTION
jordanrynard

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros