WT 14

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Experiment No:14

Config:
<?php
$databaseHost = 'localhost';
$databaseName = 'student';
$databaseUsername = 'root';
$databasePassword = '';
$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword,
$databaseName);
?>

Update:
<html>
<head>
<title>Update a Record in MySQL Database</title>
</head>
<body>
<?php
include_once("config.php");
if(isset($_POST['update']))
{

$id = mysqli_real_escape_string($mysqli, $_POST['id']);


$name = mysqli_real_escape_string($mysqli, $_POST['name']);
$result = mysqli_query($mysqli, "UPDATE stud_info SET name='$name' WHERE id=$id");
echo "<h3>data updated in a database successfully."
. " Please browse your localhost php my admin"
. " to view the updated data</h3>";

}
?>
<form method = "post" action = "<?php $_PHP_SELF ?>">
<table width = "400" border =" 0" cellspacing = "1"
cellpadding = "2">

<tr>
<td width = "100">ID</td>
<td><input name = "id" type = "text"
id = "id"></td>
</tr>

<tr>
<td width = "100">Name</td>
<td><input name = "name" type = "text"
id = "name"></td>
</tr>

<tr>
<td width = "100"> </td>
<td> </td>
</tr>

<tr>
<td width = "100"> </td>
<td>
<input name = "update" type = "submit"
id = "update" value = "Update">
</td>
</tr>
</table>
</form>
</body>
</html>

Output:
First:

Second:

Updated:

You might also like