Untitled
unknown
plain_text
a year ago
6.6 kB
9
Indexable
<?php
include './config/connection.php';
include './common_service/common_functions.php';
$message = '';
if (isset($_POST['save_Product'])) {
$productName = trim($_POST['product_name']);
$productName = ucwords(strtolower($productName));
if ($productName != '') {
$query = "INSERT INTO products(name) VALUES('$productName');";
try {
$con->beginTransaction();
$stmtProduct = $con->prepare($query);
$stmtProduct->execute();
$con->commit();
$message = 'Product added successfully.';
} catch(PDOException $ex) {
$con->rollback();
echo $ex->getMessage();
echo $ex->getTraceAsString();
exit;
}
}
header("Location:congratulation.php?goto_page=products.php&message=$message");
exit;
}
try {
$query = "SELECT id, name FROM products ORDER BY name ASC;";
$stmtProduct1 = $con->prepare($query);
$stmtProduct1->execute();
} catch(PDOException $ex) {
echo $ex->getMessage();
echo $ex->getTraceAsString();
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include './config/site_css_links.php';?>
<?php include './config/data_tables_css.php';?>
<title>Products - Inventory Management System</title>
</head>
<body class="hold-transition sidebar-mini dark-mode layout-fixed layout-navbar-fixed">
<div class="wrapper">
<?php include './config/header.php'; include './config/sidebar.php';?>
<div class="content-wrapper">
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1>Products</h1>
</div>
</div>
</div>
</section>
<section class="content">
<div class="card card-outline card-primary rounded-0 shadow">
<div class="card-header">
<h3 class="card-title">Add Product</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
<i class="fas fa-minus"></i>
</button>
</div>
</div>
<div class="card-body">
<form method="post">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-10">
<label>Product Name</label>
<input type="text" id="product_name" name="product_name" required="required"
class="form-control form-control-sm rounded-0"/>
</div>
</div>
<div class="clearfix"> </div>
<div class="row">
<div class="col-lg-11 col-md-10 col-sm-10 xs-hidden"> </div>
<div class="col-lg-1 col-md-2 col-sm-2 col-xs-12">
<button type="submit" id="save_Product" name="save_Product"
class="btn btn-primary btn-sm btn-flat btn-block">Save</button>
</div>
</div>
</form>
</div>
</div>
</section>
<br/>
<br/>
<br/>
<section class="content">
<div class="card card-outline card-primary rounded-0 shadow">
<div class="card-header">
<h3 class="card-title">Total Products</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
<i class="fas fa-minus"></i>
</button>
</div>
</div>
<div class="card-body">
<div class="row table-responsive">
<table id="all_products"
class="table table-striped dataTable table-bordered dtr-inline"
role="grid" aria-describedby="all_products_info">
<thead>
<tr>
<th>S.No</th>
<th>Product Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
while($row = $stmtProduct1->fetch(PDO::FETCH_ASSOC)){
$count++;
?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo $row['name'];?></td>
<td>
<a href="update_product.php?id=<?php echo $row['id'];?>" class="btn btn-primary btn-sm btn-flat">
<i class="fa fa-edit"></i>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</section>
</div>
<?php
include './config/footer.php';
$message = '';
if(isset($_GET['message'])) {
$message = $_GET['message'];
}
?>
<?php include './config/site_js_links.php'; ?>
<?php include './config/data_tables_js.php'; ?>
<script>
showMenuSelected("#mnu_products", "#mi_products");
var message = '<?php echo $message;?>';
if(message !== '') {
showCustomMessage(message);
}
$(function () {
$("#all_products").DataTable({
"responsive": true, "lengthChange": false, "autoWidth": false,
"buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
}).buttons().container().appendTo('#all_products_wrapper .col-md-6:eq(0)');
});
</script>
</body>
</html>
Editor is loading...
Leave a Comment