3 Replies - 322 Views - Last Post: 22 February 2013 - 07:45 PM Rate Topic: -----

#1 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 127
  • Joined: 30-January 13

why are comments not being saved in form

Posted 22 February 2013 - 03:03 AM

Here is my code I can not figure out why my comments are not being saved if the user would enter something wrong and be redirected all fields should be remembered but comments are not for some reason please submit my error and the correct way so I may fix it thanks.
<?php
function printForm($strMessage){
echo "<strong>" .$strMessage."</strong>";
echo "<form method=\"post\" action=\"" .$_SERVER['PHP_SELF']. "\" name=\"form\">\n<br>";
echo "Your Name: <input type=\"text\" Name=\"yname\" value=\"" .trim($_POST['yname'])."\"><br>";
echo "Your Email: <input type=\"text\" Name=\"yemail\" value=\"" .trim($_POST['yemail'])."\"><br>";
echo "Username: <input type=\"text\" Name=\"yusername\" value=\"" .trim($_POST['yusername'])."\"><br>";
echo "Password: <input type=\"password\" Name=\"pword\" value=\"" .trim($_POST['pword'])."\"><br>";
echo "Confirm Password: <input type=\"password\"  Name=\"cpword\" value=\"" .trim($_POST['cpword'])."\"><br>";


echo "Comments: <textarea name=\"comments\" rows=\"5\" cols=\"20\"></textarea><br>";






echo "<input type=\"submit\" value=\"send\" Name=\"submit\"/>\n<br>";
echo "</form>\n";
}

?>
<html>
<head>
<title>Self Submitting Sticky Form</title>
<style>body {
				background-color:red;
				}

</style>
</head>
<body>
    <?php
    if(isset($_POST['submit'])){
        $yourname=trim($_POST['yname']);
        $youremail=trim($_POST['yemail']);
        $yourusername=trim($_POST['yusername']);
		$yourpassword=trim($_POST['pword']);
        $yourcpassword=trim($_POST['cpword']);


       if ($yourname==''){
        $strMessage='Please enter your name.';
        printForm($strMessage);
        }
        elseif ($youremail==''){
		        $strMessage='Please enter your email.';
		        printForm($strMessage);
        }
        elseif ($yourusername==''){
				        $strMessage='Please enter your username.';
				        printForm($strMessage);
        }
        elseif ($yourpassword==''){
				        $strMessage='Please enter your password.';
				        printForm($strMessage);
        }
        elseif ($yourcpassword==''){
				        $strMessage='Please confirm your password.';
				        printForm($strMessage);
        }
        elseif ($yourcpassword != $yourpassword){
				        $strMessage='passwords must match.';
				        printForm($strMessage);
        }
        elseif(strlen($yourpassword) <= 3 ){
        $strMessage='passwords must be at least 4 characters.';
        printForm($strMessage);
        }


        else{
        $strMessage='Thank you. your information was sent.';
        echo $strMessage;
        }
     }
     else{
     $strMessage='Please enter all fields below:';
     printForm($strMessage);
     }


     ?>
     </body>
     </html>









Is This A Good Question/Topic? 0
  • +

Replies To: why are comments not being saved in form

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: why are comments not being saved in form

Posted 22 February 2013 - 04:03 AM

echo "Comments: <textarea name=\"comments\" rows=\"5\" cols=\"20\"></textarea><br>";


It is because you are using <textarea> as an empty tag, by not providing any text in it.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#3 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: why are comments not being saved in form

Posted 22 February 2013 - 04:11 AM

Try this and see if it helps.
echo "Comments: <textarea name=\"comments\" rows=\"5\" cols=\"20\" >".trim($_POST['comments'])."</textarea><br>";


regards,
Raghav
Was This Post Helpful? 2
  • +
  • -

#4 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 127
  • Joined: 30-January 13

Re: why are comments not being saved in form

Posted 22 February 2013 - 07:45 PM

thanks so much it works perfect now its just little things like that, that sometimes you look at them so much you can be blinded to a error like mine lol I really appreciate the help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1