From 71a5768da1b297c807beee4e3c6a4942126c66e9 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Thu, 28 Sep 2023 16:29:16 +0530 Subject: Lab06: Creating a MySQL Database with PHP and Storing HTML Form Data --- Lab06/form1_submit.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Lab06/form1_submit.php (limited to 'Lab06/form1_submit.php') diff --git a/Lab06/form1_submit.php b/Lab06/form1_submit.php new file mode 100644 index 0000000..f1cb514 --- /dev/null +++ b/Lab06/form1_submit.php @@ -0,0 +1,34 @@ + + + + Welcome
+ Your email address is:
+ "; + print_r($_POST); + echo ""; + $servername = "localhost"; + $username = "it"; + $password = "smit#1234"; + $dbname = "it_202000096"; + //Create connection + $conn = mysqli_connect($servername, $username, $password,$dbname); + //Check connection + if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); + } + $fname= $_POST['fname']; + $lname= $_POST['lname']; + $age= $_POST['age']; + $gender= $_POST['gender']; + $email= $_POST['email']; + $sql = "INSERT INTO student (fname, lname, age, gender,email) VALUES ('$fname','$lname','$age','$gender','$email')"; + if (mysqli_query($conn, $sql)) { + echo "New record created successfully"; + } else { + echo "Error: " . $sql . "
" . mysqli_error($conn); + } + mysqli_close($conn); + ?> + + -- cgit v1.2.3