0% found this document useful (0 votes)
22 views4 pages

Inventory Management PHP Script

This document contains PHP code to connect to a MySQL database, insert data into a table, and display and delete items from the table. It connects to a database called inventory, defines a connection, includes the connection file, and has a form to insert product name, description, price, and quantity into the inventory_m table. It then displays all items from that table in a table and allows deleting items by submitting a hidden ID field.

Uploaded by

shagufta yaseen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Inventory Management PHP Script

This document contains PHP code to connect to a MySQL database, insert data into a table, and display and delete items from the table. It connects to a database called inventory, defines a connection, includes the connection file, and has a form to insert product name, description, price, and quantity into the inventory_m table. It then displays all items from that table in a table and allows deleting items by submitting a hidden ID field.

Uploaded by

shagufta yaseen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Ubaid ur Rehman

Roll no: SP21-134


Connection:

<?php
$servername="localhost:3307"; #localhost:3307
$username="root";
$password="";
$dbname="inventory";
$conn=mysqli_connect($servername,$username,$password,$dbname);
if ($conn) {
echo "connection successful!";
}
else{
echo "connection failed!".mysqli_connect_error();
}
?>

Insert code:

<?php include("connection.php");
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Entry</title>
</head>
<body>
<form action="",method="post">
<label for="">Product Name</label>
<input type="text" name="product" id="">
<br><br>
<label for="">Description</label>
<input type="text" name="description" id="">
<br><br>
<label for="">Price</label>
<input type="text" name="price" id="">
<br><br>
<label for="">Quantity</label>
<input type="text" name="quantity" id="">
<br><br>
<button name="insertd",value="insertd">Insert</button>
</form>

</body>
</html>

<?php

if(isset($_POST['insertd']))

{ $product=$_POST['product'];
$price=$_POST['price'];
$description=$_POST['description'];
$quantity=$_POST['quantity'];
$insert="INSERT INTO `inventory_m`(`product_name`,
`description`, `price`, `quantity`) VALUES
( '$product','$description','$price','$quantity')";
$result = mysqli_query($conn, $insert);

if ($result) {
echo "Product inserted successfully";
} else {
echo "not add";
}

?>

Show & delete idtem:

<form method="post">

<table >
<tr>
<th>Product Name</th>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
<th>Action</th>
</tr>

<?php
$query = "SELECT * FROM `inventory_m`";
$result = mysqli_query($conn, $query);

while ($row = mysqli_fetch_array($result)) {


?>

<tr>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['price']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td>
<form method="post">
<input type="hidden" name="id" value="<?php echo $row['id'];
?>">
<input type="submit" name="delete" value="Delete">
</form>
</td>
</tr>

<?php
}
?>

</table>
</form>

<?php
if (isset($_POST['delete'])) {
$id = $_POST['id'];
$query = "DELETE FROM `inventory_m` WHERE `id` = $id";
mysqli_query($conn, $query);
}
?>

You might also like