Jump to content

Recommended Posts

Hi, I have the following HTML form

Using PHP, how do I display error messages above the form, upon the user not entering a data?

 

Also, if the user does enter valid data, how do I submit the form?

 

<html>
<body>

<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/102358-form-error-messages/
Share on other sites

if you want to make sure all fields are filled in put.

$firstname = $_POST["firstname"]

$lastname = $_POST["lastname"]

$age = $_POST["age"]

if($firstname && $lastname && $age)

{echo "all fields are filled in";}

else

{

echo "please fill in all fields";

}

 

this should send you in the right direction, this goes in the submit form.

to echo onto the page add require_once 'page_name.php'; in the else curly brackets

Link to comment
https://forums.phpfreaks.com/topic/102358-form-error-messages/#findComment-524119
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.