We help IT Professionals succeed at work.
Get Started

php embed in html bug

Last Modified: 2012-05-11
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.


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";

 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>

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE