Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
27 views

PHP 2

Uploaded by

aaronpinheiro84
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

PHP 2

Uploaded by

aaronpinheiro84
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Create a MySQL table student with fields roll no, name, mark, grade.

Write a PHP program to


insert

data and display the mark list of a student by accepting the register no of the student.

Insert.php

<?php

// Database connection

$servername = "localhost";

$username = "root"; // Use your MySQL username

$password = ""; // Use your MySQL password

$dbname = "nithin";

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error)

die("Connection failed: " . $conn->connect_error);

// Insert Data into student table

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['insert']))

$roll_no = $_POST['roll_no'];

$name = $_POST['name'];

$mark = $_POST['mark'];

$grade = $_POST['grade'];

$sql = "INSERT INTO student (roll_no, name, mark, grade) VALUES ('$roll_no', '$name', '$mark',
'$grade')";
if ($conn->query($sql) === TRUE) {

echo "New record created successfully";

} else {

echo "Error: " . $sql . "<br>" . $conn->error;

?>

<!DOCTYPE html>

<html>

<head>

<title>Insert Student Data</title>

</head>

<body>

<h2>Insert Student Data</h2>

<form method="POST" action="">

Roll No: <input type="text" name="roll_no" required><br><br>

Name: <input type="text" name="name" required><br><br>

Mark: <input type="text" name="mark" required><br><br>

Grade: <input type="text" name="grade" required><br><br>

<input type="submit" name="insert" value="Insert">

</form>

</body>

</html>

Delete.php

<?php

// Database connection

$servername = "localhost";
$username = "root";

$password = "";

$dbname = "nithin";

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

// Fetch student data based on roll number

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['search'])) {

$roll_no = $_POST['roll_no'];

$sql = "SELECT * FROM student WHERE roll_no = '$roll_no'";

$result = $conn->query($sql);

if ($result->num_rows > 0) {

echo "<h2>Mark List</h2>";

while ($row = $result->fetch_assoc()) {

echo "Roll No: " . $row["roll_no"]. "<br>";

echo "Name: " . $row["name"]. "<br>";

echo "Mark: " . $row["mark"]. "<br>";

echo "Grade: " . $row["grade"]. "<br>";

} else {

echo "No record found";

}
?>

<!DOCTYPE html>

<html>

<head>

<title>Search Student</title>

</head>

<body>

<h2>Search Student Mark List</h2>

<form method="POST" action="">

Enter Roll No: <input type="text" name="roll_no" required><br><br>

<input type="submit" name="search" value="Search">

</form>

</body>

</html>

You might also like