PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
-- Create the students table CREATE TABLE students ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, class VARCHAR(50) NOT NULL ); -- Create the grades table CREATE TABLE grades ( id INT AUTO_INCREMENT PRIMARY KEY, student_id INT, test_name VARCHAR(100) NOT NULL, score INT NOT NULL, test_date DATE NOT NULL, FOREIGN KEY (student_id) REFERENCES students(id) );
Copy Clear
Copy Format Clear
<?php if ($_SERVER["REQUEST_METHOD"] === "POST") { $name = $_POST['name']; $class = $_POST['class']; // Perform database insertion // (Assuming you have a database connection established) $sql = "INSERT INTO students (name, class) VALUES ('$name', '$class')"; $result = mysqli_query($conn, $sql); if ($result) { echo "Student added successfully"; } else { echo "Error adding student: " . mysqli_error($conn); } mysqli_close($conn); } ?> <!-- Your HTML form for adding a new student --> <form method="post" action="add_student.php"> <!-- ... (form fields) ... --> </form>
Show:  
Copy Clear