Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using JAVASCRIPT make this file have the following input validation it just should be an Pop-up alert using javascript if the field is empty, thats

Using JAVASCRIPT make this file have the following input validation

it just should be an Pop-up alert using javascript if the field is empty, thats it

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.php

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"; } } ?>

------------------------------------------------------------------------------------------------------ index.php

include_once("config.php");

$result = mysqli_query($mysqli, "SELECT * FROM users ORDER BY id DESC"); ?>

Homepage Add New Data Search while($res = mysqli_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } ?>

First Name Last Name Age Email Address Phone Number City State Zip Code Username Password Birth Date Relationship Update
".$res['name']." ".$res['lastname']." ".$res['age']." ".$res['email']." ".$res['address']." ".$res['phonenumber']." ".$res['city']." ".$res['state']." ".$res['zip']." ".$res['username']." ".$res['password']." ".$res['birthdate']." ".$res['relationship']." Edit | Delete

-------------------------------------------------------------------------------------------------------- add.html

in add.html i just have the form that submits new values to the database and works with add.php

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

Students also viewed these Databases questions