WANT TO ADD A preg_match to this form on the Course field for user input validation before it enters the database. The Condition I want is: ('/^[A-Z]{3}[0-9]{3}/') Kindly add the preg_match condition on course field for me. Thank you. THE CODE:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I WANT TO ADD A preg_match to this form on the Course field for user input validation before it enters the database.
The Condition I want is: ('/^[A-Z]{3}[0-9]{3}/')
Kindly add the preg_match condition on course field for me.
Thank you.

THE CODE:

<!DOCTYPE html>
<html>
  
<head>
<style>
  


  
</style>

</head>

<body>
<div class ="formdiv">
<h2> FORM VALIDATE</h2>

<form action="" method="post">
<table>
  
<tr>
<td>First Name</td>
<td><input type="text" name="fname"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lname"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="email" name="email"></td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td>Qualification</td>
<td><input type="text" name="qual"></td>
</tr>
<tr>
<td>Course</td>
<td><input type="text" name="course"></td>
</tr>

<tr>
<td colspan="2" style="text-align: center;"><input type="submit" value="Submit"></td>
</tr>
  
</table>
</form>
</div>


<?php
if(isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['email']) &&
isset($_POST['age']) && isset($_POST['qual'])&& isset($_POST['course'])){
echo '<div style="width: 400px;text-align: center;margin: 210px auto;border: 1px solid black;color:#606060FF;background-color: #D6ED17FF;">';
// get the form input values and store in variables
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$email = $_POST['email'];
$age = $_POST['age'];
$qualifiacation = $_POST['qual'];
$course = $_POST['course'];

// if input boxes are blank, error message is shown
if($firstname == "" || $lastname == "" || $email == "" ||
$age == "" || $qualifiacation == "" || $course == ""){
echo '<h2> Please input all fields </h2>';
}

else{
$servername = "localhost";
$username = "root";
$password = "password";
$databasename = "user_data";
  
// Create connection
$conn = new mysqli($servername, $username, $password, $databasename);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
  
$sql = "INSERT INTO user_details (first_name, last_name, email, age, qualification, Course)
VALUES ('$firstname', '$lastname', '$email', '$age', '$qualifiacation', '$course')";
  
if ($conn->query($sql) === TRUE) {
echo "<h1>Hello ". $firstname." ". $lastname ."</h1>";
echo "<h2 style =color:#606060FF;background-color:#D6ED17FF;>Form data has been sent to database successfully.</h2>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
  
$conn->close();
}
}

?>

</div>

</body>
</html>

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Parallel Processing
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY