Form PHP Mysql
Form PHP Mysql
Project I
Item.html
<html>
<body>
<h1>Items Information</h1>
<b><form action="item.php" method="GET">
ItemId:<input type="text" name="id"><br>
ItemName:<input type="name" name="name"><br>
ItemType:<select name="type">
<option value="Computer">Computer</option>
<option value="House Hold">House Hold</option>
<option value="Others">Others</option>
</select><br>
Price:<input type="number" name="price"><br>
<input type="submit"></form></b>
</body></html>
Project II
2.
a.
create table items(Itemid int primary key, ItemName varchar(30),Status char, ManufacturedDate date);
b. Save by Home.html
<html>
<body>
<br>
<table>
<tr>
</tr>
</table>
<br>
Click on the menu given above to insert, retrieve or modify records this Official Pages for IP-
Section B Students.
</body></html>
c. Save by insert.html
html>
<body>
<br>
<table>
<tr>
</table>
<br>
<h1>Customers Information</h1>
Sex:<select name="sex">
<option value="M">M</option>
<option value="F">F</option>
</select><br>
<input type="submit"></form></b>
<body></html>
d) Save by insert.php
<html>
<body>
<br>
<table><tr>
<?php
$con=mysqli_connect("localhost","root","meti","supermarket");
// Check connection
if (mysqli_connect_errno())
VALUES
('$_POST[id]','$_POST[name]','$_POST[sex]','$_POST[dob]')";
if (!mysqli_query($con,$sql))
?>
<?php
mysqli_close($con);
?>
</body></html>
e) save by update.html
<html>
<body>
<br>
<table>
<tr>
</tr>
</table>
<br>
<body></html>
f) save by update.php
<html>
<body>
<br>
<table><tr>
<?php
$con=mysqli_connect("localhost","root","meti","supermarket");
// Check connection
if (mysqli_connect_errno())
if (!mysqli_query($con,$sql))
?>
<?php
mysqli_close($con);
</body></html>
g) save by delete.html
<html>
<body>
<br>
<table>
<tr>
</tr>
</table>
<br>
Enter the Id of the customer you want to delete from the table.
<body></html>
h) save by delete.php
<html>
<body>
<br>
<table>
<tr>
</tr>
</table>
<br>
<?php
$inp=$_POST[id];
$con=mysqli_connect("localhost","root","","supermarket");
// Check connection
if (mysqli_connect_errno())
$rec=0;
$f=0;
while($row = mysqli_fetch_array($result))
$rec=$row['Customerid'];
if($inp==$rec)
echo "<b>";
echo "</b>";
$f+=1;
if($f==0)
echo "<b>";
echo "</b>";
mysqli_close($con);
?>
<body></html>
i)save by display.html
<html>
<body>
<br>
<table>
<tr>
</tr>
</table>
<br>
<h1>Customers Information</h1>
<?php
$con=mysqli_connect("localhost","root","meti","supermarket");
// Check connection
if (mysqli_connect_errno())
<tr><td>Customerid</td><td>CustomerName</td><td>Sex</td><td>DateOfBirth</td></tr></
b>";
while($row = mysqli_fetch_array($result))
echo "<tr>";
echo "</table>";
mysqli_close($con);
?>
</table>
</body></html>
<body>
<br>
<table>
<tr>
</tr>
</table>
<br>
<h1>Customer Information</h1>
<?php
$id=$_POST[id];
$con=mysqli_connect("localhost","root","meti","supermarket");
// Check connection
if (mysqli_connect_errno())
if($id==$row['Customerid'])
echo "</form>";
$f+=1;
if($f==0)
mysqli_close($con);
?>
</table>
</body></html>
<?php
$connection=mysqli_connect("localhost","root","");
if($connection){
$sql="create database registrar";
if(mysqli_query($connection,$sql))
echo "Database Created Successfully";
else
die("Database not created:".mysqli_error($connection));
mysqli_close($connection);
}else
die("connection failed:".mysqli_error($connection));
?>
2. Create a table called course that contains the following attributes under registrar database.
(createtable.php)
<?php
$connection=mysqli_connect("localhost","root","");
if($connection){
if(mysqli_select_db($connection,"registrar")){
$sql="create table course(
CCode varchar(10) primary key,
CTitle varchar(25),
CrHr integer)";
if(mysqli_query($connection,$sql))
echo "Table Created Successfully";
else
die("Table not created:".mysqli_error($connection));
}
mysqli_close($connection);
}else
die("connection failed:".mysqli_error($connection));
3. Create the following form and write php scripts that allow users to insert course information
into course table though the form.(registercourse.php)
14 Prepared By:-Samuel A. Internet Programming Form+PHP+MYsql Lab worksheet
<html><body>
<h1>Course Registration Form</h1><hr>
<?php
if(isset($_POST["register"])){
$ccode=$_POST["ccode"];
$ctitle=$_POST["ctitle"];
$crhr=$_POST["crhr"];
$connection=mysqli_connect("localhost","root","","registrar");
if($connection)
{
$sql="Insert into course(CCode,CTitle,CrHr)values('$ccode','$ctitle','$crhr')";
if(mysqli_query($connection,$sql))
echo "<b><i><font color=red>Record inserted successfully</font></i></b>";
else
die("Record not inserted:".mysqli_error($connection));
mysqli_close($connection);
}else
die("connection failed:".mysqli_error($connection));
}
?>
<form action="" method="post">
<table><tr><td>Course Code:<input type="text" name="ccode" required></td></tr>
<tr><td>Course Title:<input type="text" name="ctitle" required></td></tr>
<tr><td>Credit Hour:<input type="number" name="crhr" required></td></tr>
<tr><td><input type="submit" value="Register" name="register"> <input type="reset" name="reset"
value="Reset"></td></tr></table>
</form><hr></body></html>
4. Write a php script that displays all the registered courses from course table in the following
format.(viewcourse.php)
}else if(isset($_POST["save"]))
{
$ccode=$_POST["ccode"];
$ctitle=$_POST["ctitle"];
$crhr=$_POST["crhr"];
$sql="update course set CTitle='$ctitle',CrHr='$crhr' where CCode='$ccode'";
if(mysqli_query($con,$sql))
echo "Course detail updated successfully";
else
die("Record not updated:".mysqli_error($con));
}else if(isset($_POST["delete"]))
{
$ccode=$_POST["ccode"];
$sql="delete from course where CCode='$ccode'";
if(mysqli_query($con,$sql))
echo "Record deleted successfully";
else
die("Record not deleted:".mysqli_error($con));
}
}else
die("Connection Failed:".mysqli_error($con));
?></body></html>