Jump to content

How to give error messages


tempguy

Recommended Posts

I wanna give error messages if the user dont enter their name, email or comments. I trıed to do it but mine didnt work. Please help me do it.

 

 

 

Index.php page

 

<html>

<head>
<title>Guestbook</title>
</head>

<body>

<font color="#CC0000" size="+2">Please sign our guestbook</font> <br \> <br \>

<?php

echo "<form name=\"Guestbook\" action=\"confirm.php\" method=\"post\">\n";
echo "<table bgcolor=\"#DAE5CD\">\n";
echo "  <tr>\n";
echo "    <td valign=\"top\">Name: </td>\n";
echo "    <td><input type=\"text\" name=\"name\" size=\"25\" value=\"Your Name\"></td>\n";
echo "  </tr>\n";
echo "  <tr>\n";
echo "    <td valign=\"top\">E-mail:</td>\n";
echo "    <td><input type=\"text\" name=\"email\" size=\"25\" value=\"example@mail.com\"></td>\n";
echo "  </tr>\n";
echo "  <tr>\n";
echo "    <td valign=\"top\">Comments:</td>\n";
echo "    <td><textarea rows=\"5\" cols=\"30\" name=\"comments\">Comments</textarea></td>\n";
echo "     </tr>\n";
echo "  <tr>\n";
echo "    <td></td>\n";
echo "       <td align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Submit\">  
      <input type=\"reset\" value=\"Clear\"> </td>\n";
echo "  </tr>\n";
echo "</table>\n";
echo "</form> ";

?>
</body>
</html>

 

confirm.php page

 

<html>
<head>
<title> Submission receieved!  </title>
</head>

<body>
<font size="+2" color="#00B0EB">Your submission has been sent successfully!</font><br /> <br />

<?php

//extract($_REQUEST);

if (!isset($_POST["$submit"]))
{

	if (empty($_POST["name"]))
	{
	    echo "Please enter your name!";
	        }
	else if (empty($_POST["email"]))
	{
	    echo "Please enter your E-mail";
	        }
	else if (empty($_POST["comments"]))
	{
	    echo "Please enter some text";
	        }
}

?>

<table bgcolor="#DAE5CD" width="%50" cellpadding="5">
    <tr>
        <td valign="top" width="75">Name : </td>
        <td> <?php echo $_POST["name"];?> </td>
    </tr>
    <tr>
        <td valign="top">E-Mail : </td>
        <td> <?php echo $_POST["email"]; ?> </td>
    </tr>
    <tr>
        <td valign="top">Comments :</td>
        <td> <?php echo $_POST["comments"]; ?> </td>
    </tr>
</table>

</body>
</html>

Link to comment
Share on other sites

This should probably be changed:

  if (!isset($_POST["$submit"]))
   

 

Into:

  if (isset($_POST["submit"]))
  

 

If you do the !isset($_POST['submit']), then your validation won't run if $_POST['submit'] exists, which it does the moment you submit your form as your submit input is named "submit"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.