PR 5
PR 5
5.1 : Write PHP script to connect my SQL server from your website.
<html>
<body>
<h3> Program to collect the customer-information </h3>
<form action ="Display.php" method="get">
<table border="5">
<tr>
<td> Enter Name:</td>
<td> <input type="text" name="name"> </td>
</tr>
<tr>
<td> Enter Address Line1: </td>
<td> <input type="text" name="address1"></td>
</tr>
<tr>
<td> Enter Email-id: </td>
<td> <input type="text" name="email"> </td>
</tr>
<tr>
<td> </td> </tr>
<tr> </tr>
<tr>
<td> <input type="submit" value="Submit"></td>
<td> <input type="Reset" value="Reset"></td>
</tr>
</br>
<a href="<a href="https://krazytech.com/programs/simple-library-management-
system-php-mysql" target="_blank" rel="noopener">Search.html</a>"> To search
click here </a> </td>
</table>
</form>
</body>
</html>
Output:-
5.3 : Write a program to edit name of customer to Bob with cust_no = 1, and to
delete record with cust_no = 3.
<html>
<body>
<form action="processorder.php" method="post">
<table style="border: 0px;">
<tr style="background: #cccccc;">
<td style="width: 150px; text-align: center;">Item</td>
<td style="width: 15px; text-align: center;">Quantity</td>
</tr>
<tr>
<td>Tires</td>
<td><input type="text" name="tireqty" size="3"
maxlength="3" /></td>
</tr>
<tr>
<td>Oil</td>
<td><input type="text" name="oilqty" size="3"
maxlength="3" /></td>
</tr>
<tr>
<td>Spark Plugs</td>
<td><input type="text" name="sparkqty" size="3"
maxlength="3" /></td>
</tr>
<tr>
<td colspan="2" style="text-align: center;"><input type="submit"
value="Submit
Order" /></td>
</tr>
</table>
</form>
</body>
</html>
Output :
<html>
<head>
<title>Update a Record in MySQL Database</title>
</head>
<body>
<?php
if(isset($_POST['update']))
{
$dbhost = '';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$emp_id = $_POST['emp_id'];
$emp_salary = $_POST['emp_salary'];
mysql_select_db('');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Employee ID</td>
<td><input name="emp_id" type="text" id="emp_id"></td>
</tr>
<tr>
<td width="100">Employee Salary</td>
<td><input name="emp_salary" type="text" id="emp_salary"></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>
<?php
}
?>
</body>
</html>
Output: