<?php
include('includes/db.php');
?>
<?php include('functions/functions.php'); ?>
<?php
include('header.php');
?>
<?php
include('topheader.php');
?>
<?php
include('nav.php');
?>
<div id="content">
<div class="container">
<div class="col-md-12">
<ul class="breadcrumb">
<li>Home</li>
<li>Cart</li>
</ul> <!--breadcrumb ends--->
</div> <!---col-md-12 ends-->
<div class="col-md-9" id="cart">
<div class="box">
<form action="cart.php" method="post" enctype="multipart-form-data">
<h1>Shopping Cart</h1>
<?php
$ip_add = getUserIP();
$select_cart = "select * from cart where ip_add='$ip_add'";
$run_cart = mysqli_query($conn, $select_cart);
$count = mysqli_num_rows($run_cart);
?>
<p class="text-muted">You currently have <?php echo $count; ?> items in your cart</p>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th colspan="2">Product</th>
<th>Quantity</th>
<th colspan="1">Unit Price</th>
<th>Container</th>
<th colspan="1">Delete</th>
<th colspan="2">Sub Total</th>
</tr>
</thead> <!--thead ends-->
<tbody>
<?php
$total = 0;
while ($row_cart = mysqli_fetch_array($run_cart)) {
$pro_id = $row_cart['p_id'];
$pro_size = $row_cart['size'];
$pro_qty = $row_cart['qty'];
$get_products = "select * from products where product_id='$pro_id'";
$run_products = mysqli_query($conn, $get_products);
while ($row_products = mysqli_fetch_array($run_products)) {
$product_title = $row_products['product_title'];
$product_img1 = $row_products['product_img1'];
$only_price = $row_products['product_price'];
$sub_total = $row_products['product_price'] * $pro_qty;
$total += $sub_total;
}
?>
<tr>
<td><img src="admin_area/product_images/<?php echo $product_img1; ?>"></td>
<td><?php echo $product_title; ?></td>
<td><?php echo $pro_qty; ?></td>
<td>₹<?php echo $only_price; ?>.00</td>
<td><?php echo $pro_size ?></td>
<td><input type="checkbox" name="remove[]" value="<?php echo $pro_id; ?>"></td>
<td>₹<?php echo $sub_total; ?>.00</td>
</tr> <!---tr ends-->
<?php } ?>
</tbody>
<tfoot>
<tr>
<th colspan="5">TOTAL</th>
<th colspan="2">₹ <?php echo $total; ?>.00</th>
</tr>
</tfoot> <!--tfoot ends-->
</table> <!--table ends-->
</div> <!---table-responsive end-->
<div class="box-footer">
<div class="pull-left">
<a href="index.php" class="btn btn-default">
<i class="fa fa-chevron-left"></i>Continue Shopping
</a>
</div> <!--pullleft ends-->
<div class="pull-right">
<button class="btn btn-default" type="submit" name="update" value="Update Cart"><i class="fa fa-refresh"></i>Update Cart </button>
<a href="checkout.php" class="btn btn-primary">
Proceed to checkout<i class="fa fa-chevron-right"></i>
</a>
</div> <!--pullright ends-->
</div> <!----box footer ends-->
</form> <!---form ends-->
</div> <!---box ends-->
<?php
function update_cart() {
global $conn;
if (isset($_POST['update'])) {
foreach ($_POST['remove'] as $remove_id) {
$delete_product = "delete from cart where p_id='$remove_id'";
$run_delete = mysqli_query($conn, $delete_product);
if ($run_delete) {
echo "<script>window.open('cart.php','_self')</script>";
}
}
}
}
echo #$up_cart = update_cart();
?>
<div class="row same-height-row">
<div class="col-md-3 col-md-6">
<div class="box same-height headline">
<h3 class="text-center">Recently Viewed Product</h3>
</div> <!----box same-height headline end-->
</div> <!---col-m-3 col-md-6 ends---->
<?php
$get_products = "select * from products order by rand() LIMIT 0,3";
$run_products = mysqli_query($conn, $get_products);
while ($row_products = mysqli_fetch_assoc($run_products)) {
$pro_id = $row_products['product_id'];
$pro_title = $row_products['product_title'];
$pro_price = $row_products['product_price'];
$pro_img1 = $row_products['product_img1'];
echo "<div class='center-responsive col-md-3 col-sm-6'>
<div class='product same-height'>
<a href='details.php?pro_id=$pro_id'>
<img src='admin_area/product_images/$pro_img1' class='img-responsive'>
</a>
<div class='text'>
<h3><a href='details.php?pro_id=$pro_id'>$pro_title</a></h3>
<p class='price'>₹ $pro_price</p>
</div>
</div>
</div>";
}
?>
</div>
</div>
<div class="col-md-3">
<div class="box" id="order-summary">
<div class="box-header">
<h3>Order Summary</h3>
</div> <!--box-header ends-->
<p class="text-muted">
Shipping and additional costs are calulated based on the value you have entered.
</p>
<div class="table-responsive">
<table class="table">
<tbody>
<tr>
<td>Order Subtotal</td>
<th>₹<?php echo $sub_total; ?></th>
</tr>
<tr>
<td>Shipping and Handling</td>
<td>₹0.00</td>
</tr>
<tr>
<td>Tax</td>
<td>₹0.00</td>
</tr>
<tr class="total">
<td>Total</td>
<th>₹ <?php echo $total; ?></th>
</tr>
</tbody>
</table> <!--table ends-->
</div> <!---table responsive ends-->
</div> <!---box ends-->
</div> <!----col-md-3 ends--->
</div> <!--container ends-->
</div> <!---content ends-->
<?php include_once 'footer.php'; ?>
i get undefined variable sub_total even after defining variable subtotal above. Can someone figure out what the problem is?? I have check all curly brackets and semicolen. Due on a project that needs to be submited tomorrow. I am thinking improving the coding later but the basic functionality is not working.
Related
So to sum up my problem and what I'm trying to do:
I'm trying to code an Attendance feature in my PHP Website where the admin first chooses the Class he wants to mark the Attendance for, and then he's taken to a new page with a table that ONLY displays students from THAT class. He enter the date/status of each student and presses Submit, and multiple rows are inserted into the "attendance" table.
Now, this was working perfectly before. The only new addition to this feature was the "Class" feature, now each student has a class (you might call it grade in your region). Before, they didn't.
So naturally, the table's SELECT query went from
$rows2 = $conn->query("SELECT * FROM students")->fetchAll(PDO::FETCH_ASSOC);
to:
$rows2 = $conn->query("SELECT * FROM students WHERE grade_id = $grade")->fetchAll(PDO::FETCH_ASSOC);
This little addition has completely messed up my INSERT query, which works fine when I exclude the "WHERE" clause. Below, I'm attaching code for two pages - one is ChooseClass.php where admin picks the Class he wants to add Attendance for. This page basically sends the chosen class ID to the 2nd page, which is AddAttendance.php.
ChooseClass.php:
<?php include('../db.php');
session_start();
$email = $_SESSION["email"];
$user = $conn->query("SELECT * from admin where email = '$email' ")->fetchAll(PDO::FETCH_ASSOC);
$userID = $user[0]['admin_id'];
$someotherRow = $conn->query("SELECT * FROM grade")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<?php include('adminheader.php'); ?>
<body style="background-color: #5e72e4 !important;">
<!-- Sidenav -->
<?php include('adminsidebar.php'); ?>
<div class="main-content" id="panel">
<!-- Topnav -->
<?php include('admintopbar.php'); ?>
<!-- Header -->
<!-- Header -->
<div class="header bg-primary pb-6" style="background-color: #5e72e4 !important;">
<div class="container-fluid">
<div class="header-body">
<div class="row align-items-center py-4">
<div class="col-lg-6 col-7">
<h6 class="h2 text-white d-inline-block mb-0">Attendance Managament</h6>
</div>
</div>
<!-- Card stats -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<!-- Card body -->
<div class="card-header">Choose a Class</div>
<div class="card-body">
<div class="table-responsive" style="overflow-y: scroll; height: 600px;">
<table class="table align-items-center table-dark table-flush">
<thead class="thead-dark">
<tr>
<th scope="col" class="sort" data-sort="name">Class Name</th>
<th scope="col" class="sort" data-sort="status">Action</th>
</tr>
</thead>
<tbody class="list">
<?php
foreach ($someotherRow as $row) { ?>
<tr>
<th scope="row">
<div class="media align-items-center">
<div class="media-body">
<span class="name mb-0 text-sm"><?php echo $row['grade_name']; ?></span>
</div>
</div>
</th>
<td>
<form action="" method="POST">
<a type="submit" href="adminmarkattendance.php?gradeid=<?php echo $row['grade_id']; ?> " class="btn btn-primary">Select</a>
</form>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Page content -->
<div class="container-fluid mt--6">
<!-- background-color: #5e72e4 !important; height: 63.9vh; -->
</div>
</div>
</body>
</html>
AddAttendance.php:
<?php include('../db.php');
session_start();
$email = $_SESSION["email"];
$user = $conn->query("SELECT * from admin where email = '$email' ")->fetchAll(PDO::FETCH_ASSOC);
$userID = $user[0]['admin_id'];
$grade = 0;
if (isset($_GET['gradeid'])) {
$grade = $_GET['gradeid'];
}
$rows2 = $conn->query("SELECT * FROM students WHERE grade_id = $grade")->fetchAll(PDO::FETCH_ASSOC);
$count = count($rows2);
if (isset($_POST["submit"])) {
for ($i = 0; $i < $count; $i++) {
$student_id = $_POST["id"][$i];
$status = $_POST['options'][$i];
$grade_id = $_POST['grade_id'];
$date = $_POST['attendancedate'];
$date = date('Y-m-d', strtotime($date));
$queryInsert = $conn->prepare("INSERT
into attendance
(
student_id,
grade_id,
date,
status
)
values
(
$student_id,
$grade_id,
'$date',
'$status'
)
");
$queryInsert->execute();
}
echo "<script> location.replace('chooseclass.php'); </script>";
}
?>
<!DOCTYPE html>
<html>
<?php include('adminheader.php'); ?>
<body style="background-color: #5e72e4 !important;">
<!-- Sidenav -->
<?php include('adminsidebar.php'); ?>
<div class="main-content" id="panel">
<!-- Topnav -->
<?php include('admintopbar.php'); ?>
<!-- Header -->
<!-- Header -->
<div class="header bg-primary pb-6" style="background-color: #5e72e4 !important;">
<div class="container-fluid">
<div class="header-body">
<div class="row align-items-center py-4">
<div class="col-lg-6 col-7">
<h6 class="h2 text-white d-inline-block mb-0">Mark Attendance</h6>
</div>
</div>
<!-- Card stats -->
<div class="row">
<div class="col-lg-12">
<form action="adminmarkattendance.php" method="post">
<div class="row">
<div class="col">
<div class="card bg-default shadow">
<div class="card-header bg-transparent border-0">
<div class="form-inline">
<div class="col-lg-6">
<h3 class="text-white mb-0">Registered Students</h3>
</div>
<div class="col-lg-6">
<div class="form-group">
<input style="width: 100%;" class="form-control" name="attendancedate" type="date" required>
</div>
</div>
</div>
</div>
<div class="table-responsive" style="overflow-y: scroll; height: 600px;">
<table class="table align-items-center table-dark table-flush">
<thead class="thead-dark">
<tr>
<th scope="col" class="sort" data-sort="name">Avatar</th>
<th scope="col" class="sort" data-sort="name">Student Name</th>
<th scope="col" class="sort" data-sort="status">Phone Number</th>
<th scope="col" class="sort" data-sort="status">Age</th>
<th scope="col" class="sort" data-sort="status">Gender</th>
<th scope="col" class="sort" data-sort="status">Address</th>
<th scope="col" class="sort" data-sort="status">Action</th>
</tr>
</thead>
<tbody class="list">
<?php
foreach ($rows2 as $row) { ?>
<tr>
<td>
<img src="<?php echo '../profileImages/' . $row['profile_image'] ?>" width="45" height="45" alt="">
<input type="hidden" name="id[]" value="<?php echo $row['student_id']; ?>">
<input type="hidden" name="grade_id" value="<?php echo $grade ?>">
</td>
<th scope="row">
<div class="media align-items-center">
<div class="media-body">
<span class="name mb-0 text-sm"><?php echo $row['fname'] . ' ' . $row['lname']; ?></span>
</div>
</div>
</th>
<td>
<span class="badge badge-dot mr-4">
<span class="status"><?php echo $row['phonenumber']; ?></span>
</span>
</td>
<td>
<span class="badge badge-dot mr-4">
<span class="status"><?php echo $row['age']; ?></span>
</span>
</td>
<td>
<span class="badge badge-dot mr-4">
<span class="status"><?php echo $row['gender']; ?></span>
</span>
</td>
<td>
<span class="badge badge-dot mr-4">
<span class="status"><?php echo $row['address']; ?></span>
</span>
</td>
<td>
<select class="form-control" name="options[]">
<option value="Present" selected>Present</option>
<option value="Absent">Absent</option>
</select>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="text-center">
<button type="submit" name="submit" style="width: 100%;" class="btn btn-warning">Mark Attendance</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Page content -->
<div class="container-fluid mt--6">
<!-- background-color: #5e72e4 !important; height: 63.9vh; -->
</div>
</div>
</body>
</html>
I've spent 2 hours looking at this code and I can't figure out why the addition of WHERE breaks my code. I've also var_dumped most of the variables, just to check if I was entering some NULL value and I'm not. So kindly look into it and see if you can figure out why data is not being inserted into the database..
You are sending gradeid value in -
href="adminmarkattendance.php?gradeid= "
And getting value in AddAttendance.php
So, first give right path and second, there is also a space within ahref. So, when you try to get the value use trim, it will remove spaces -
$grade = trim($_GET['gradeid']);
I don't want duplicate column name of company_name and when I click collapse bootstrap it shows the table values that has the same name of company_name
this is output now
<?php
$stmt=$conn->prepare("SELECT DISTINCT company_name,project,po_number FROM company");
$stmt->execute();
$result=$stmt->get_result();
?>
<div class="accordion" id="accordionExample">
<?php while($row = mysqli_fetch_array($result)){?>
<div class="card">
<div class="card-header" >
<h2 class="mb-0">
<a class="btn cat" type="button" data-toggle="collapse" href="#c<?=$row['company_name']?>" role="button" aria-expanded="false">
<?php echo $row['company_name'] ?>
</a>
</h2>
</div>
<div id="c<?=$row['company_name']?>" class="collapse">
<div class="card-body">
<div class="table-responsive ">
<table class="table table-hover table-borderless" id="table1">
<thead>
<tr class="text-truncate">
<th>Po</th>
<th>ชื่อโครงการ</th>
<th>ผู้รับผิดชอบ</th>
<th>รายละเอียด</th>
</tr>
</thead>
<tbody>
<?php $c; ?>
<tr class="<?=($c++%2==1) ? 'odd' : 'even' ?>">
<td><?php echo $row['po_number'] ?></td>
<td><?php echo $row['project'] ?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
I want my collapse show like this hope you understand
https://i.stack.imgur.com/ZtwEe.png
Perhaps it will be cleanest to create a grouped array structure from your result set, then use nested loops to generate the output from the new structure.
Suggested Code:
<?php
$sql = "SELECT DISTINCT company_name, project, po_number FROM company";
$grouped = [];
foreach ($conn->query($sql) as $row) {
$grouped[$row['company_name']][] = [
'project' => $row['project'],
'po_number' => $row['po_number']
];
}
// now generate markup...
?>
<div class="accordion" id="accordionExample">
<?php foreach ($grouped as $companyName => $details) { ?>
<div class="card">
<div class="card-header">
<h2 class="mb-0">
<a class="btn cat" type="button" data-toggle="collapse"
href="#c<?=$companyName?>" role="button" aria-expanded="false"
>
<?=$companyName?>
</a>
</h2>
</div>
<div id="c<?=$companyName?>" class="collapse">
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover table-borderless">
<thead>
<tr class="text-truncate">
<th>Po</th>
<th>ชื่อโครงการ</th>
<th>ผู้รับผิดชอบ</th>
<th>รายละเอียด</th>
</tr>
</thead>
<tbody>
<?php foreach ($details as $i => $detail) { ?>
<tr class="<?=$i & 1?'odd':'even'=>">
<td><?=$detail['po_number']?></td>
<td><?=$detail['project']?></td>
<td></td>
<td></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
I was set up my index page with pending order,sales and completed order. Each and every minutes that data are changed.so i decided to refresh particular div by jquery and got succeed by changing data dynamically.But issues start on my style.When the div was reloded style of card was distract.I dont know why this happened.
<div class="row" >
<div class="col-xl-3 col-lg-3 col-md-6 col-sm-12 col-12" id="here">
<div class="row">
<div class="col-xl-12">
<div class="card border-3 border-top border-top-primary">
<div class="card-body">
<h5 class="text-muted">Total Sales</h5>
<div class="metric-value d-inline-block">
<h1 class="mb-1 text-center"><? if($total != '') { echo "Rs: ".$total; } else { echo "Rs: 0";} ?></h1>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card border-3 border-top border-top-primary">
<div class="card-body">
<h5 class="text-muted">Complted Order</h5>
<div class="metric-value d-inline-block">
<h1 class="mb-1 text-center"><?= $complte." Nos"; ?></h1>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card border-3 border-top border-top-primary">
<div class="card-body">
<h5 class="text-muted">Pending Order</h5>
<div class="metric-value d-inline-block">
<h1 class="mb-1 text-center"><?= $pending." Nos"; ?></h1>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-9 col-lg-12 col-md-6 col-sm-12 col-12">
<?
$orderquery = mysqli_query($conn,"SELECT * FROM ordermaster o LEFT JOIN customer c ON o.custid = c.custid WHERE o.status = 'p' AND orderdt = CURRENT_DATE() ");
?>
<div class="card">
<h5 class="card-header">Recent Orders</h5>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table">
<thead class="bg-light">
<tr class="border-0">
<th class="border-0">#</th>
<th class="border-0">Name</th>
<th class="border-0">Phone</th>
<th class="border-0">Address</th>
<th class="border-0">Pincode</th>
<th class="border-0">City</th>
<th class="border-0">Order Time</th>
<th class="border-0">Amount</th>
<th class="border-0">View</th>
</tr>
</thead>
<tbody>
<?
$count = 1;
while($res = mysqli_fetch_array($orderquery))
{
?>
<tr>
<td><?= $count; ?></td>
<td><?= $res['name']; ?> </td>
<td><?= $res['phone']; ?> </td>
<td><?= $res['addr1']."/".$res['addr2']; ?> </td>
<td><?= $res['pincode']; ?> </td>
<td><?= $res['city']; ?> </td>
<td><?= $res['orderdtm']; ?> </td>
<td><?= $res['net']; ?> </td>
<td><button class="btn btn-sm btn-outline-primary" title="View Product" onclick="del('<? echo $res['orderid'];?>')" value="id" data-toggle="modal" data-target="#delete" data-backdrop="static" data-keyboard="false"><i class="fas fa-eye"></i></button></td>
</tr>
<?
$count++;
}
?>
<tr>
<td colspan="9">View Details</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
and my jquery coding to reload div is
$(document).ready(function(){
setInterval(function(){
$("#here").load(window.location.href + " #here" );
}, 3000);
});
whats error going on i cann't understand.image before apply load
image after load
To stop the loop you can use clearInterval()
Jquery replace with this
$(document).ready(function(){
window.setInterval(function(){
$("#here").load(window.location.href + " #here");
}, 3000);
clearInterval()
});
I'm trying to hide an included file with a condition.
<?php include('header_dashboard.php'); ?>
<?php include('session.php'); ?>
<?php $get_id = $_GET['id']; ?>
<?php
$post_id = $_GET['post_id'];
if($post_id == ''){
?>
<script>
window.location = "assignment_student.php<?php echo '?id='.$get_id; ?>";
</script>
<?php
}
?>
<body id="studentTableDiv">
<?php include('navbar_student.php'); ?>
<div class="container-fluid">
<div class="row-fluid">
<?php include('assignment_link_student.php'); ?>
<div class="span6" id="content">
<div class="row-fluid">
<!-- breadcrumb -->
<?php $class_query = mysqli_query($conn, "select * from teacher_class
LEFT JOIN class ON class.class_id = teacher_class.class_id
LEFT JOIN subject ON subject.subject_id = teacher_class.subject_id
where teacher_class_id = '$get_id'")or die(mysqli_error());
$class_row = mysqli_fetch_array($class_query);
?>
<ul class="breadcrumb">
<li><?php echo $class_row['class_name']; ?> <span class="divider">/</span></li>
<li>Asignaciones <span class="divider">/</span></li>
<li><b>Subir Asignación</b></li>
</ul>
<!-- end breadcrumb -->
<!-- block -->
<div id="block_bg" class="block">
<div class="navbar navbar-inner block-header">
<div id="" class="muted pull-left"></div>
</div>
<div class="block-content collapse in">
<div class="span12">
<?php
$query1 = mysqli_query($conn, "select * FROM assignment where assignment_id = '$post_id'")or die(mysqli_error());
$row1 = mysqli_fetch_array($query1);
?>
<div class="alert alert-info">Subir respuesta de asignacion en : <?php echo $row1['fname']; ?></div>
<div id="">
<table cellpadding="0" cellspacing="0" border="0" class="table" id="">
<thead>
<tr>
<th>Fecha Subida</th>
<th>Nombre de Archivo</th>
<th>Descripción</th>
<th>Enviado por:</th>
<th>Calificación</th>
</tr>
</thead>
<tbody>
<?php
$query = mysqli_query($conn, "select * FROM student_assignment LEFT JOIN student on student.student_id = student_assignment.student_id where assignment_id = '$post_id' order by assignment_fdatein DESC")or die(mysqli_error());
while($row = mysqli_fetch_array($query)){
$id = $row['student_assignment_id'];
$student_id = $row['student_id'];
?>
<tr>
<td><?php echo $row['assignment_fdatein']; ?></td>
<td><?php echo $row['fname']; ?></td>
<td><?php echo $row['fdesc']; ?></td>
<td><?php echo $row['firstname']." ".$row['lastname']; ?></td>
<?php if ($session_id == $student_id){ ?>
<td>
<span class="badge badge-success"><?php echo $row['grade']; ?></span>
</td>
<?php }else{ ?>
<td></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /block -->
</div>
</div>
<?php include('submit_assignment_sidebar.php') ?>
</div>
<?php include('footer.php'); ?>
</div>
<?php include('script.php'); ?>
</body>
</html>
<?php include('submit_assignment_sidebar.php') ?>
OK what I'm trying to do is move this include that is at the end
<?php include('submit_assignment_sidebar.php') ?>
To:
<?php if ($session_id == $student_id){ ?>
<td>
<span class="badge badge-success"><?php echo $row['grade']; ?></span>
</td>
<?php }else{ ?>
<td></td>
<?php include('submit_assignment_sidebar.php') ?>
<?php } ?>
But it doesn't work. Doesn't include de sidebar file. Any sugestion?
I development admin control panel in my system when i update some thing in category the data not updated. what the error of my code? for more help you can download my files from here http://www.mediafire.com/download/m9psmr55pib5555/update_category.rar
<form action="categories.php" method="post">
<label>Edit category</label>
<?php
/*start of select data */
if(isset($_GET['edit_cat'])){
$cat_id = $_GET['edit_cat'];
$update_cat ="SELECT * FROM categories WHERE cat_id= $cat_id";
$run_cat_id = mysqli_query($connect , $update_cat);
while($row =mysqli_fetch_assoc($run_cat_id)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_name'];
?>
<div class="form-group">
<!--to pick the value -->
<input value="<?php if(isset($cat_title)){echo $cat_title;} ?>" type="text" class="form-control" name="cat_name">
</div>
<?php }}?>
<?php
if(isset($_POST['update'])){
$cat_update = $_POST['cat_name'];
$query ="UPDATE categories SET cat_name ='{$cat_update}' WHERE cat_id ={$cat_id}";
$update_query= mysqli_query($connect , $query);
<?php
ob_start();
include("includes/header.php");
include("includes/db.php");
?>
<div id="page-wrapper">
<div class="container-fluid">
<?php
if(isset($_GET['edit_cat'])){
$cat_id = $_GET['edit_cat'];
include ("includes/update_category.php");
}
?>
</div>
<!-- end of category form -->
</div>
<!--
===========================================================================================================
-->
<!-- start of table to show categories-->
<div class="col-lg-6">
<div class="btn btn-success"><h3>categories</h3></div>
<div class="table-responsive" >
<table class="table table-bordered table-hover">
<thead>
<tr>
<th width="10px">Id</th>
<th width="400px">category title</th>
</tr>
</thead>
<tbody>
<?php
/*Select from DB to show categories in table*/
$i=1;
$query = "SELECT *FROM categories";
$run_cat = mysqli_query($connect , $query);
while($row = mysqli_fetch_assoc($run_cat)){
$cat_id = $row['cat_id'];
$cat_name =$row ['cat_name'];
?>
<tr>
<td><?php echo $i++;?></td>
<td><?php echo $cat_name; ?></td>
<td><div class='btn btn-warning' name="edit_cat"><i class='fa fa-pencil-square-o fa-2'></i> Edit</div></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- end of table to show categories-->
<!-- =============================================================================
-->
</div>
</div>
</div>
</body>
</html>
if(!$update_query){
die("QUERY FAILED".mysqli_error($connect));
}
}
?>
<div class="form-group">
<input type="submit" name="update" value="submit" class="btn btn-success"/>
</div>
</form>