Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using JAVASCRIPT make this file use the following input validation The current code is in PHP so add/change what is needed in so all of

Using JAVASCRIPT make this file use the following input validation

The current code is in PHP so add/change what is needed in so all of the input validation is in JAVASCRIPT

Form Validation:

In this assignment there will be 5 things to validate:

1- Validate that the names are filled in, first and last name

2- Validate that they are letters, upper case and lower case. (You can use /^[a-zA-Z]+$/ as the regular expression)

3- Check to make sure the phone number is all numbers. (You can use /^[0-9]+$/ as the regular expression)

4- If they are updating the form make sure the form is filled out completely.

5- If they are creating a new record make sure they filled the form out completely.

If any of these fields are not met then the form will produce an alert and let them know what they are missing.

Add Data

include_once("config.php"); if(isset($_POST['Submit'])) { $name = $_POST['name']; $lastname = $_POST['lastname']; $age = $_POST['age']; $email = $_POST['email']; $address = $_POST['address']; $phonenumber = $_POST['phonenumber']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $username = $_POST['username']; $password = $_POST['password']; $birthdate = $_POST['birthdate']; $relationship = $_POST['relationship']; // checking empty fields if(empty($name) || empty($lastname) || empty($age) || empty($email)|| empty($address)|| empty($phonenumber)|| empty($city)|| empty($state)|| empty($zip)|| empty($username)|| empty($password)|| empty($birthdate)|| empty($relationship)) { if(empty($name)) { echo "Name field is empty.
"; } if(empty($lastname)) { echo "Last Name field is empty.
"; } if(empty($age)) { echo "Age field is empty.
"; } if(empty($email)) { echo "Email field is empty.
"; } if(empty($address)) { echo "Address field is empty.
"; } if(empty($phonenumber)) { echo "Phone Number field is empty.
"; } if(empty($city)) { echo "City field is empty.
"; } if(empty($state)) { echo "State field is empty.
"; } if(empty($zip)) { echo "Zip Code field is empty.
"; } if(empty($username)) { echo "Username field is empty.
"; } if(empty($password)) { echo "Password field is empty.
"; } if(empty($birhdate)) { echo "Birhdate field is empty.
"; } if(empty($relationship)) { echo "Relationship field is empty.
"; } //link to the previous page echo "
Go Back"; } else { // if all the fields are filled (not empty) //insert data to database $result = mysqli_query($mysqli, "INSERT INTO users(name,lastname,age,email,address,phonenumber,city,state,zip,username,password,birthdate,relationship) VALUES('$name','$lastname','$age','$email','$address','$phonenumber','$city','$state','$zip','$username','$password','$birthdate','$relationship')"); //display success message echo "Data added successfully."; echo "
View Result"; } } ?>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions