forked from AtitBimali/web-tech-labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab_assignment_10formsubmit.php
More file actions
37 lines (31 loc) · 1.01 KB
/
lab_assignment_10formsubmit.php
File metadata and controls
37 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
// Establish a connection to the MySQL server
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "student";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Process form data and insert into the database
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$fullName = $_POST["fullName"];
$course = $_POST["course"];
$semester = $_POST["semester"];
$email = $_POST["email"];
$phoneNo = $_POST["phoneNo"];
// Insert data into the "student_info" table
$sql = "INSERT INTO student_info (fullName, course, semester, email, phoneNo) VALUES ('$fullName', '$course', '$semester', '$email', '$phoneNo')";
if ($conn->query($sql) === TRUE) {
echo "Record inserted successfully!";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
} else {
echo "Invalid request method";
}
// Close the database connection
$conn->close();
?>