0% found this document useful (0 votes)
5 views1 page

Update A Database Using PHP

This document contains an HTML form for updating a student's age based on their registration number. It includes PHP code to connect to a MySQL database and execute an update query when the form is submitted. The script provides feedback on whether the update was successful or if no record was found for the given registration number.

Uploaded by

bholdi
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)
5 views1 page

Update A Database Using PHP

This document contains an HTML form for updating a student's age based on their registration number. It includes PHP code to connect to a MySQL database and execute an update query when the form is submitted. The script provides feedback on whether the update was successful or if no record was found for the given registration number.

Uploaded by

bholdi
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/ 1

1 <html>

2 <body>
3 <form action="" method="post">
4 Enter Reg No to be updated<input type="text" name="x"></br>
5 Enter New Age<input type="text" name="age"></br>
6 <input type="submit" value="Search"><input type="reset" value="clear">
7 </form>
8 </body></html>
9
10 <?php
11 $servername='localhost';
12 $username='root';
13 $password="";
14 $dbname='bsc';
15
16 $conn = mysqli_connect($servername, $username, $password,$dbname);
17
18 if (!$conn)
19 {
20 die("Connection failed:".mysqli_connect_error());
21 }
22 else if($_SERVER['REQUEST_METHOD']=="POST")
23 {
24 $regno=$_POST['x'];
25 $new_age=$_POST['age'];
26
27 $sql = "UPDATE student set age='$new_age' WHERE regNo='$regno'";
28 $result = mysqli_query($conn, $sql);
29
30 if ($result)
31 {
32 if (mysqli_affected_rows($conn) > 0) {
33 echo "<h3>Update successful for Reg No: $regno</h3>";
34 } else {
35 echo "<h3>No record found with Reg No: $regno</h3>";
36 }
37 }
38
39 }
40 . uytre
41 ;LKJ X C
42 +
43 >
44

You might also like