0% found this document useful (0 votes)
8 views

PHP 16

The document describes code for updating data in a student table in a database. The code includes an HTML form to input update values and a PHP script to connect to the database and execute an UPDATE SQL query based on the submitted form values.

Uploaded by

Omkar Mahajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

PHP 16

The document describes code for updating data in a student table in a database. The code includes an HTML form to input update values and a PHP script to connect to the database and execute an UPDATE SQL query based on the submitted form values.

Uploaded by

Omkar Mahajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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