You are on page 1of 2

Name : Rushikesh Uttarwar Practical no : 16

Roll no : 26

 Code for updating data in student table


Code :
.html
<!DOCTYPE html>
<html>
<head>
<title>Update Values in Database</title>
</head>
<body>
<h1>Update values in database</h1> <form action="update.php" method="post">
Enter roll no of student you want to update his data:
<input type="text" name="roll_no">
Name:
<input type="text" name="name">
Age:
<input type="text" name="age">
Class:
<input type="text" name="class">
<button type="submit" name="submit_update">Submit</button>
</form></body></html>
.php
<?php

$servername = "localhost";
$username = "root";
$password = "";
$database = "aditya";
$conn = mysqli_connect($servername, $username, $password, $database);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connection successful.....<br>";
if (isset($_POST['submit_update'])) {
$roll_no = $_POST['roll_no'];
$name = $_POST['name'];
$age = $_POST['age'];
$class = $_POST['class'];
$sql = "UPDATE `Student` SET `name`='$name', `age`='$age', `class`='$class' WHERE
`roll_no`='$roll_no'";
if (mysqli_query($conn, $sql)) {
echo "Data updated successfully";
} else {
Name : Rushikesh Uttarwar Practical no : 16
Roll no : 26
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}mysqli_close($conn);
?>
Output :
Before updateing :

After updating:

You might also like