1<?php
2//including the database connection file
3include("config.php");
4if(isset($_POST['Submit'])) {
5$pname = $_POST['pname'];
6$pcode = $_POST['pcode'];
7$pprice = $_POST['pprice'];
8
9// checking empty fields
10if(empty($pname) || empty($pcode) || empty($pprice)) {
11if(empty($pname)) {
12echo "<font color="red">Product Name field is empty.</font><br>";
13}
14if(empty($pcode)) {
15echo "<font color="red">Product Code field is empty.</font><br>";
16}
17if(empty($pprice)) {
18echo "<font color="red">Product Price field is empty.</font><br>";
19}
20//link to the previous page
21 echo "<br><a href="javascript:self.history.back();">Go Back</a>";
22 } else {
23// if all the fields are filled (not empty)
24//insert data to database
25$result = mysqli_query($cser, "INSERT INTO crud2(pname,pcode,pprice) VALUES('$pname','$pcode','$pprice')");
26
27//display success message
28echo "<font color="green">Data added successfully.</font>";
29
30}
31}
32?>
33