summaryrefslogtreecommitdiff
path: root/Lab06/create_table.php
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-09-28 16:29:16 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-09-28 16:29:16 +0530
commit71a5768da1b297c807beee4e3c6a4942126c66e9 (patch)
tree6a21f670cebf2b8ec7bdebf9ab92e589589bdce2 /Lab06/create_table.php
parentc2f4b5442c065c2a7a6288ce46ed409aa054d8bb (diff)
Lab06: Creating a MySQL Database with PHP and Storing HTML Form Data
Diffstat (limited to 'Lab06/create_table.php')
-rw-r--r--Lab06/create_table.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/Lab06/create_table.php b/Lab06/create_table.php
new file mode 100644
index 0000000..f11a89b
--- /dev/null
+++ b/Lab06/create_table.php
@@ -0,0 +1,37 @@
+<?php
+$servername = "localhost";
+$username = "it";
+$password = "smit#1234";
+$database = "it_202000096";
+$tableName = "studentdb";
+
+//Create connection
+$conn = new mysqli($servername, $username, $password);
+
+//Check connection
+if ($conn->connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+}
+
+//Select the database
+$conn->select_db($database);
+
+//Create table
+$sql = "CREATE TABLE `$tableName` (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ fname VARCHAR(50) NOT NULL,
+ lname VARCHAR(50) NOT NULL,
+ age INT,
+ gender VARCHAR(10),
+ phone VARCHAR(15),
+ email VARCHAR(100)
+)";
+
+if ($conn->query($sql) === TRUE) {
+ echo "Table created successfully";
+} else {
+ echo "Error creating Table: " . $conn->error;
+}
+
+$conn->close();
+?>