-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadddata.php
More file actions
35 lines (31 loc) · 1.19 KB
/
Copy pathadddata.php
File metadata and controls
35 lines (31 loc) · 1.19 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
<?php
$conn = require_once "conn.php"; // Assuming this file contains the PDO connection
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$grade = $_POST['grade'];
$marks = $_POST['marks'];
// Check if all fields are filled
if (!empty($name) && !empty($grade) && !empty($marks)) {
try {
// Prepare an insert statement using named placeholders
$sql = "INSERT INTO results (name, class, marks) VALUES (:name, :grade, :marks)";
$stmt = $conn->prepare($sql);
// Bind values to placeholders
$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->bindValue(':grade', $grade, PDO::PARAM_STR);
$stmt->bindValue(':marks', $marks, PDO::PARAM_INT); // Assuming 'marks' is an integer
// Execute the statement
if ($stmt->execute()) {
header("Location: index.php");
exit();
} else {
echo "Something went wrong. Please try again later.";
}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
} else {
echo "Name, Class, and Marks cannot be empty!";
}
}
?>