summaryrefslogtreecommitdiff
path: root/Lab03/insert.php
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-08-24 22:52:23 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-08-24 22:52:23 +0530
commitf5e5cfa6c26e6f41af74c33a5a6726e50ef164f1 (patch)
treec0a3b93b0af000933071da36351e2f9c7488b8b2 /Lab03/insert.php
parent97e177c102a0bd32580c5f8b99d620924dae4a61 (diff)
Lab03 - Create a Registration form using HTML Forms
Diffstat (limited to 'Lab03/insert.php')
-rw-r--r--Lab03/insert.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/Lab03/insert.php b/Lab03/insert.php
new file mode 100644
index 0000000..a7efb70
--- /dev/null
+++ b/Lab03/insert.php
@@ -0,0 +1,42 @@
+<?php
+
+$servername = "localhost";
+$username = "db_user";
+$password = "password123";
+$dbname = "regform";
+
+// Create connection
+$conn = new mysqli($servername,
+ $username, $password, $dbname);
+
+// Check connection
+if ($conn->connect_error) {
+ die("Connection failed: "
+ . $conn->connect_error);
+}
+
+$fname = $_REQUEST['fname'];
+$lname = $_REQUEST['lname'];
+$gender = $_REQUEST['gender'];
+$regno = $_REQUEST['regno'];
+$phone = $_REQUEST['phone'];
+$email = $_REQUEST['email'];
+$department = $_REQUEST['department'];
+
+$sql = "INSERT INTO $dbname VALUES ('$fname','$lname','$gender','$regno','$email',$department)";
+
+if(mysqli_query($conn, $sql)){
+ echo "<h3>data stored in a database successfully."
+ . " Please browse your localhost php my admin"
+ . " to view the updated data</h3>";
+
+ echo nl2br("\n$first_name\n $last_name\n "
+ . "$gender\n $address\n $email");
+} else{
+ echo "ERROR: Could not insert the data values $sql. "
+ . mysqli_error($conn);
+}
+
+// Close connection
+mysqli_close($conn);
+?> \ No newline at end of file