what you would learn
- You will learn how to use preg_match function to search strings for required pattern
- You will learn how to use filter_var function to check valid email entry
- You will learn how to check if an entered input like email already exist in a database.
Requirements
- A text edditor
- An apache and SQL sever
- A browser
Tutorial Contents
You might have a form on your website and you want to make sure that users fill in the required information before submission
First you must have created a form page and it looks like this
[IMAGE: https://res.cloudinary.com/hpiynhbhq/image/upload/v1520157487/oqcdodnp7qprsyoovjtf.png]
output should look like this
[IMAGE: https://res.cloudinary.com/hpiynhbhq/image/upload/v1520157531/grtif5kmms51vbbsqrnh.png]
Next you create a div class that contains the error message and style it to color red it looks like this
[IMAGE: https://res.cloudinary.com/hpiynhbhq/image/upload/v1520157591/vv4beoxniugvvanesnkc.png]
Then you write the PHP code for validation, here we use pregmatch, test_input and strlen.
Note: we are putting our PHP code in the same page as our form then use the PHP_SELF super global
Create a data base and a table that collects the information from the form so let’s use database “test” and table “validate” take a look at the table
[IMAGE: https://res.cloudinary.com/hpiynhbhq/image/upload/v1520157759/bsfsvv7k73feazfyxxnb.png]
Now put your action attribute and use “($_SERVER["PHP_SELF"])” with method as “post” then call for the error message by putting this code “