CONNECTION.PHP

<?php

$con = mysqli_connect('localhost','root','','bakery') or die("Connection Error");

if($con)
{
echo"SUCESS";
}
else{
echo"ERROR";
}

?>

INDEX.PHP

<?php

include "connection.php";

if(isset($_POST['submit']))
{
$name = $_POST['txtname'];
$price = $_POST['txtprice'];
$quantity = $_POST['textquantity'];

$data = mysqli_query($con,"INSERT INTO item VALUES(NULL,'$name','$price','$quantity')");

if($data)
{
echo"Data Inserted";
}
else
{
echo"Not Inserted";
}
header("location: display.php");
}
?>

<html>
<head>
<title>ADD ITEM</title>
</head>
<body bgcolor="#EEF2FB">
<center>
<h1 style="color:2BABEB">-----: ITEM :-----</h1>
<form action="index.php" method="POST">
ITEM Name :
<input type="text" name="txtname" size="33" style="background-color: #EEF2FB; border-style: solid;border-width: 2px;border-color: #2BABEB; padding: 10px 20px; margin: 4px 2px; cursor: space; Border-radius:10px; Font-size:15px";> <br><br>
ITEM Price :
<input type="text" name="txtprice" size="33" style="background-color: #EEF2FB; border-style: solid;border-width: 2px;border-color: #2BABEB; padding: 10px 20px; margin: 4px 2px; cursor: space; Border-radius:10px; Font-size:15px";> <br><br>
ITEM Quantity :
<input type="text" name="textquantity" size="30" style="background-color: #EEF2FB; border-style: solid;border-width: 2px;border-color: #2BABEB; padding: 10px 20px; margin: 4px 2px; cursor: space; Border-radius:10px; Font-size:15px";> <br><br>

⎗
✓
<input type="submit" name="submit" value="Submit" style="background-color: #2BABEB; border: none; color:#FFFFFF; padding: 15px 30px; text-decoration: none;margin: 8px 4px; cursor: pointer; Border-radius:10px; Font-size:20px";>

</center>
</form>
</body>
</html>

DISPLAY.PHP

<?php

include "connection.php";

$data = mysqli_query($con,"SELECT * FROM item");

?>

<center>

<h1 style ="color:#2BABEB">Product Details</h1>
<table style="padding:20px" border="5px" bordercolor="2BABEB" width="80%" cellspacing="20" padding="30px" align="center">
<tr>
<th bgcolor=#EEF2FB style="color:#2BABEB;padding:15px">ID</th>
<th bgcolor=#EEF2FB style="color:#2BABEB">NAME</th>
<th bgcolor=#EEF2FB style="color:#2BABEB">PRICE</th>
<th bgcolor=#EEF2FB style="color:#2BABEB">QUANTITY</th>
<th bgcolor=#EEF2FB colspan="2" style="color:#2BABEB">ACTION</th>
</tr>
<?php
while($row = mysqli_fetch_array($data))
{
?>
<tr>
<td style="padding:10px" align="center"bgcolor=#EEF2FB><?php echo $row['id']; ?></td>
<td align="center" bgcolor=#EEF2FB><?php echo $row['name']; ?></td>
<td align="center" bgcolor=#EEF2FB><?php echo $row['price']; ?></td>
<td align="center" bgcolor=#EEF2FB><?php echo $row['quantity']; ?></td>
<td align="center" bgcolor= #b8ffa9><a href="update.php?edit_id=<?php echo $row['id']; ?>" style="color:green"> UPDATE </a> </td>
<td align="center" bgcolor=#FFCDD2><a href="delete.php?del_id=<?php echo $row['id']; ?>" style="color:red"> DELETE </a> </td>
</tr>
<?php
}
?>
</table>
</center>

UPDATE.PHP

<?php
include "connection.php";
if(isset($_GET['edit_id']))
{
$sql = "SELECT * FROM item WHERE id=" .$_GET['edit_id'];

$result = mysqli_query($con,$sql);

$row = mysqli_fetch_array($result);
}

if(isset($_POST['submit']))
{
$name = $_POST['txtname'];
$price = $_POST['txtprice'];
$quantity = $_POST['txtquantity'];

$update = "UPDATE item SET name='$name', price='$price', quantity='$quantity' WHERE id=" .$_GET['edit_id'];

$edit= mysqli_query($con,$update);

if(isset($sql))
{
header("location: display.php");
}
else
{
echo "ERROR";
}
}
?>

<html>
<head>
<title>UPDATE ITEM DETAILS</title>
</head>
<body bgcolor="#EEF2FB">
<center>
<h1 style="color:2BABEB">UPDATE ITEM DETAILS</h1>
<form action="update.php?edit_id=<?php echo $row['id']; ?>" method="POST">
ITEM Name :
<input type="text" name="txtname" value="<?php echo $row['name']; ?>" size="30" style="background-color: #EEF2FB; border-style: solid;border-width: 2px;border-color: #2BABEB; padding: 10px 20px; margin: 4px 2px; cursor: space; Border-radius:10px; Font-size:15px"> <br><br>
ITEM Price :
<input type="text" name="txtprice" value="<?php echo $row['price']; ?>" size="30" style="background-color: #EEF2FB; border-style: solid;border-width: 2px;border-color: #2BABEB; padding: 10px 20px; margin: 4px 2px; cursor: space; Border-radius:10px; Font-size:15px";> <br><br>
ITEM Quantity :
<input type="text" name="txtquantity" value="<?php echo $row['quantity']; ?>" size="30" style="background-color: #EEF2FB; border-style: solid;border-width: 2px;border-color: #2BABEB; padding: 10px 20px; margin: 4px 2px; cursor: space; Border-radius:10px; Font-size:15px";> <br><br>

⎗
✓
<input type="submit" name="submit" value="Submit" style="background-color: #2BABEB; border: none; color:#FFFFFF; padding: 15px 30px; text-decoration: none;margin: 8px 4px; cursor: pointer; Border-radius:10px; Font-size:20px";>

</center>
</form>
</body>
</html>

DELETE.PHP

<?php
include "connection.php";
if(isset($_GET['del_id']))
{
$delete = "DELETE FROM item WHERE id=$_GET[del_id]";

1
2
3
mysqli_query($con,$delete);

header("location: display.php");
}
?>

ASP.NET

Imports System.Data.SqlClient

Partial Public Class _Default
Inherits System.Web.UI.Page

Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\hp\Documents\Visual Studio 2008\Projects\Collage Management\Collage Management\App_Data\Database1.mdf;Integrated Security=True;User Instance=True")

Protected Sub gridview()

⎗
✓
1
2
3
4
5
6
Dim cmd As New SqlCommand("select * from student", con)
Dim adp As New SqlDataAdapter(cmd)
Dim ds As New Data.DataSet
adp.Fill(ds)
GridView1.DataSource = ds.Tables(0)
Me.DataBind()

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

⎗
✓
gridview()

End Sub

INSERT

Protected Sub btn_insert_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_insert.Click

⎗
✓
Dim cmd As New SqlCommand("insert into student values(@id,@name,@date,@contact)", con)
cmd.Parameters.AddWithValue("@id", CInt(TextBox_id.Text))
cmd.Parameters.AddWithValue("@name", (TextBox_name.Text))
cmd.Parameters.AddWithValue("@date", (TextBox_date.Text))
cmd.Parameters.AddWithValue("@contact", (TextBox_contact.Text))

con.Open()
cmd.ExecuteNonQuery()
con.Close()

MsgBox("INSERTED")
gridview()

End Sub

UPDATE

Protected Sub btn_update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_update.Click

⎗
✓
Dim cmd As New SqlCommand("update student set name=@name,date=@date,contact=@contact where id=@id", con)
cmd.Parameters.AddWithValue("@id", CInt(TextBox_id.Text))
cmd.Parameters.AddWithValue("@name", (TextBox_name.Text))
cmd.Parameters.AddWithValue("@date", (TextBox_date.Text))
cmd.Parameters.AddWithValue("@contact", (TextBox_contact.Text))

con.Open()
cmd.ExecuteNonQuery()
con.Close()

MsgBox("UPDATED")
gridview()

End Sub

Protected Sub btn_search_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_search.Click

⎗
✓
Dim cmd As New SqlCommand("select * from student where id=@id", con)
cmd.Parameters.AddWithValue("@id", TextBox_id.Text)
con.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
dr.Read()
TextBox_name.Text = dr.Item(1).ToString
TextBox_date.Text = dr.Item(2).ToString
TextBox_contact.Text = dr.Item(3).ToString

con.Close()
MsgBox("FOUND")
gridview()

End Sub

DELETE

Protected Sub btn_delete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_delete.Click

⎗
✓
1
2
3
4
5
6
7
8
Dim cmd As New SqlCommand("delete from student  where id=@id", con)
cmd.Parameters.AddWithValue("@id", TextBox_id.Text)

con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("DELETED")
gridview()

End Sub
End Class

SHELL - gedit -> enter
Edit

Pub: 12 Oct 2023 11:21 UTC

Views: 70