I want to display the invoice bill for each customer when admin clicks on view bill button for that customer. Also I want to display all the newspaper details in a single invoice when customer name is same.I have included the relevant code and database snapshots.
c_details.php
<?php
session_start();
include_once("connect.php");
$query="SELECT * FROM sub_details";
$result=mysqli_query($conn,$query);
?>
<table align="center">
<h3 style="color: black; font-weight: bold; text-align: center;">
Subscription details</h3><br>
<tr>
<th style="text-align: center;">Id</th>
<th style="text-align: center;">Name</th>
<th style="text-align: center; width: 900px">Newspaper</th>
<th style="text-align: center;">Duration</th>
<th style="text-align: center;">Price</th>
<th style="text-align: center; width: 800px">Subscription date</th>
<th style="text-align: center;">Remaining Days</th>
<th style="text-align: center;">Bill</th>
</tr>
<?php while($rows=mysqli_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $rows['id']; ?></td>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['newspaper']; ?></td>
<td><?php echo $rows['duration']; ?></td>
<td><?php echo $rows['price']; ?></td>
<td><?php echo $rows['sdate']; ?></td>
<?php echo var_dump($result->fetch_all(MYSQLI_ASSOC));
$date1=date_create();
$date2=date_create($rows['edate']);
$interval=date_diff($date2,$date1)->format("%a days");
?>
<td><?php echo $interval; ?></td>
<td>
<form action="invoice.php" method="GET">
<?php $invoiceId = $rows['name']; ?>
<button type="submit" onclick= "window.open('invoice.php?name= '<?php echo
$rows['name']; ?>)" class="btn btn-primary btn-lg" value="submit" >
View bill</button></td>
</form>
</tr>
<?php } ?>
</table>
invoice.php
<?php
include_once("connect.php");
$invoiceId = isset($_GET['name']) ? $_GET['name'] : null;
if($invoiceId) {
$query = "SELECT * FROM sub_details WHERE name = ? limit 1";
$result = mysqli_query($conn,$query);
?>
<?php while($rows=mysqli_fetch_assoc($result)) {
?>
<form style="text-align: left;margin-left: 30px" class="register-form" id="register-form">
<div class="form-group"> Bill no: <input type="text" name="id" value="<?php echo $rows['id']; ?>"></div><br>
<div class="form-group">Name: <input type="text" name="name" value="<?php echo $rows['name']; ?>"></div><br>
<div class="form-group">Address: <input type="text" name="address" value="<?php echo $rows['address']; ?>"></div><br><br>
</form>
</th>
</tr>
<td>
<table cellpadding="5px" cellspacing="6px" style="width: 75%; border-radius:20px;">
<tr>
<th>Newspaper</th>
<th >Duration</th>
<th >Price</th>
</tr>
<tr>
<td ><?php echo $rows['newspaper']; ?></td>
<td><?php echo $rows['duration']; ?></td>
<td><?php echo $rows['price']; ?></td>
</tr>
<tr>
<td>DELIVERY CHARGES</td>
<td colspan="3" style="padding-right:60px;text-align: right;">50</td>
</tr>
<tr>
<th>Total</th>
<?php
$t_price=$rows['price']+ 50; ?>
<th colspan="3" style="text-align: right;padding-right: 55px"><?php echo $t_price; ?></th>
</tr>
<tr>
<th colspan="4" >
<br><br><br><br><br><br><br>
</th>
</tr>
</table>
</td>
<tr>
<th colspan="4" style="border-top-color: #ffff4d">
<p style="text-align: left;">Note: Clients are requested to pay the bill before 5th of every month.</p>
</th>
</tr>
<?php } ?>
</table>
Database screenshots
First, you should pass the invoice ID for each record in c_details.php so that you can identify them later:
<button type="submit" onclick= "window.open('invoice.php?id='<?php echo $rows['id']; ?>)" class="btn btn-primary btn-lg" value="submit" >View bill</button>
It will produce URLs like invoice.php?id=<id>, where <id> is the ID for each record in the database. So, for example, a record with the ID 102 will be invoice.php?id=102.
On invoice.php, you can retrieve the ID with $_GET['id']. You should adjust your query to fetch the data for the given invoice:
$invoiceId = isset($_GET['id']) ? $_GET['id'] : null;
if($invoiceId) {
$query = $conn->prepare("SELECT * FROM sub_details, signup_c WHERE id = ? limit 1";
$query->bind_param('s', $invoiceId);
$query->execute();
$result = $query->get_result();
}
If you're using PHP 7.0 or later, you can simplify your code using the null coalescing operator:
$invoiceId = $_GET['id'] ?? null;
I strongly recommend you to learn about how to prevent SQL injections in PHP.
Related
I am trying to process form fields via POST method. I will post a long code for you to inspect, however the structure of the code is simply like this
<form> <table> <th> </th> <td> </td> </table> </form>
so it is a table inside a form. When the form is submitted, I am taken to the "cart.php" page which is expected, but that page shows the echo statement and shows the variables correctly for a split second, then shows the rest of the page but the variables in the echo statement become "undefined".
P.S: Please don't mark as duplicate with this question, thanks.
This is the first page index.php
<div class="table-responsive" id="order_table">
<form method="POST" action="cart.php" class="form-group">
<table class="table table-bordered">
<tr>
<th width="40%">Product Name</th>
<th width="10%">Quantity</th>
<th width="20%">Price</th>
<th width="15%">Sub Total</th>
<th width="5%">Action</th>
</tr>
<?php
if(!empty($_SESSION["shopping_cart"]))
{
$sub_total = 0;
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
?>
<tr>
<td><?php echo $values["product_name"]; ?></td>
<td><input type="text" name="quantity[]" id="quantity<?php echo $values["product_id"]; ?>" value="<?php echo $values["product_quantity"]; ?>" data-product_id="<?php echo $values["product_id"]; ?>" class="form-control quantity" /></td>
<td align="right">$ <?php echo $values["product_price"]; ?></td>
<td align="right">$ <?php echo number_format($values["product_quantity"] * $values["product_price"], 2); ?></td>
<td><button name="delete" class="btn btn-danger btn-xs delete" id="<?php echo $values["product_id"]; ?>">Remove</button></td>
</tr>
<?php
$sub_total = $sub_total + ($values["product_quantity"] * $values["product_price"]);
$tax = $sub_total * 0.075;
$total = $sub_total + $tax;
}
?>
<tr>
<td colspan="3" align="right"><span style="font-size:1.3em;">Tax</span></td>
<td align="right">$ <?php echo number_format($tax,2); ?></td>
</tr>
<tr>
<td colspan="3" align="right"><span style="font-size:1.3em;">Total</span></td>
<td align="right">$ <?php echo number_format($total, 2); ?></td>
<td></td>
</tr>
<tr>
<td colspan="5" align="center">
<textarea name="comments" id="comment" class="form-control" placeholder="Please enter any special instructions for the order"></textarea> <br>
<input type="submit" name="place_order" id="place_order" class="btn btn-warning" value="Place Order" />
</td>
</tr>
<?php
}
?>
</table>
</form>
And this is the beginning of cart.php:
$comment = $_POST['comments'];
echo $comment. $_POST['place_order'];
print_r($_POST);
How I know that the variables do get passed is cause I noticed some result appearing for a split second so I took a video and paused it there and it had the expected POST array, before the page suddenly appears as expected but with
"Undefined index: comments "
and
"Undefined index: place_order"
and "Array()" at the top. cart.php does not have any commands that make it refresh. Thank you.
I have a table with multiple columns (index.php). One column is a checkbox. Whenever the checkbox is checked, it displays another row where you can select a quantity. You can then hit a button called "Add to Order" and it will take you to a confirmation page (index-order.php) where I want it to display each row along with all of the data in that specified row that has the checkbox checked. Currently, I am getting no errors in my console, but no data is being displayed at all.
What do I need to change to make this happen? Here is what I have so far.
Index.php code:
<form name="form1" method="POST" action="index-order.php">
<section id="addToOrder">
<button type="submit" class="order" id="order" name="order" value="AddToOrder">Add to Order</button>
</section>
<br>
<div id="my-div2" class="ui-widget">
<div class="ui-widget">
<table id="merchTable" cellspacing="5" class="sortable">
<thead>
<tr class="ui-widget-header">
<th class="sorttable_nosort"></th>
<th class="sorttable_nosort">Loc</th>
<th class="merchRow">Report Code</th>
<th class="merchRow">SKU</th>
<th class="merchRow">Special ID</th>
<th class="merchRow">Description</th>
<th class="merchRow">Quantity</th>
<th class="sorttable_nosort">Unit</th>
<th style="display: none;" class="num">Quantity #</th>
</tr>
</thead>
<tbody>
<?php foreach ($dbh->query($query) as $row) {?>
<tr>
<td class="ui-widget-content"><input type="checkbox" class="check" name="check"></td>
<td name="rows[0][0][loc]" class="loc ui-widget-content" id="loc-<?php echo intval ($row['Loc'])?>"><?php echo $row['Loc'];?></td>
<td name="rows[0][0][rp-code]" class="rp-code ui-widget-content" align="center" id="rp-code-<?php echo intval ($row['Rp-Code'])?>"><?php echo $row['Rp-Code'];?></td>
<td name="rows[0][0][sku]" class="sku ui-widget-content" id="sku-<?php echo intval ($row['SKU'])?>"><?php echo $row['SKU'];?></td>
<td name="rows[0][0][special-id]" class="special-id ui-widget-content" align="center" id="special-id-<?php echo intval ($row['Special-ID'])?>"><?php echo $row['Special-ID'];?></td>
<td name="rows[0][0][description]" class="description ui-widget-content" id="description-<?php echo intval ($row['Description'])?>"><?php echo $row['Description'];?></td>
<td name="rows[0][0][quantity]" class="quantity ui-widget-content" data-quantity="<?php echo $row['Quantity'] ?>" align="center" id="quantity-<?php echo intval ($row['Quantity'])?>"><?php echo $row['Quantity'];?></td>
<td name="rows[0][0][unit]" class="unit ui-widget-content" id="unit-<?php echo intval ($row['Unit'])?>"><?php echo $row['Unit'];?></td>
<td name="rows[0][0][quant]" style="display: none;" class="quantity_num ui-widget-content"><input type="textbox" style="width: 100px;" class="spinner" name="value" id="test"></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</form>
Index-order.php:
<?php if(isset($_POST['rows'])): ?>
<table cellspacing="20">
<tr align="center">
<th>Loc</th>
<th>Report Code</th>
<th>SKU</th>
<th>Special ID</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit</th>
<th>Quantity #</th>
</tr>
<?php
foreach($_POST['rows'][0] as $row):
?>
<tr align="center">
<td><?php echo $row['loc']; ?></td>
<td><?php echo $row['rp-code']; ?></td>
<td><?php echo $row['sku']; ?></td>
<td><?php echo $row['special-id']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quant']; ?></td>
</tr>
<?php
endforeach;
?>
</table>
I am okay with the precedent answer, I never heard about this kind of method with PHP and it doesn't seems to be the right solution. Anyway, the following post would maybe help you : How to get value from td's via $_POST.
You cannot transfer datas through POST by using td ; but an alternative would be to use the "hidden" type of forms element :
<form action="script.php" method="post">
<td class=".."><input type="hidden" name="td1" value="...">value</td>
...
</form>
In PHP, you'll grab the data with the $_POST array and the td1 name :
<?php var_dump($_POST); ?>
Itwould in my opinion be the easier way to get what you want in a proper way ; the link I gave upper is also talking about DOMDocument, but it looks more complex to manage with.
this program works properly i just don't know how to make this additional function work...
dbconfig.php
<?php
$db_host = "localhost";
$db_name = "testproduct";
$db_user = "root";
$db_pass = "";
try{
$db_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
$db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
echo $e->getMessage();
}
?>
Product Management
Here in product management I will add the product information name,price,stock etc..
add_form.php
<?php
require_once 'dbconfig.php';
if($_POST)
{
$fname = $_POST['name'];
$lname = $_POST['actualprice'];
$contactnum = $_POST['sellprice'];
$email = $_POST['Stock'];
try{
$stmt = $db_con->prepare("INSERT INTO tblproduct(name,actualprice,sellprice,Stock) VALUES(:pname,:pactualprice,:psellprice,:pStock)");
$stmt->bindParam(":pname", $name);
$stmt->bindParam(":pactualprice", $actualprice);
$stmt->bindParam(":psellprice", $sellprice);
$stmt->bindParam(":pStock", $Stock);
if($stmt->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
<style type="text/css">
#dis{
display:none;
}
</style>
<div id="dis">
</div>
<form method='post' id='emp-SaveForm' action="#">
<table class='table table-bordered'>
<tr>
<td>Product Name</td>
<td><input type='text' name='name' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td>Actual Price</td>
<td><input type='text' name='actualprice' class='form-control' placeholder='EX : Web Design, App Design' required></td>
</tr>
<tr>
<td>Sell Price</td>
<td><input type='text' name='sellprice' class='form-control' placeholder='EX : 180000' required></td>
</tr>
<tr>
<td>Stock</td>
<td><input type='text' name='Stock' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
</form>
index.php
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Product Name</th>
<th>Actual Price</th>
<th>Sell Price</th>
<th>Stock</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
$stmt = $db_con->prepare("SELECT * FROM tblproduct ORDER BY id DESC");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['actualprice']; ?></td>
<td><?php echo $row['sellprice']; ?></td>
<td><?php echo $row['Stock']; ?></td>
<td align="center">
<a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
Sales Management
here is the problem in sales I will add a sales record which will require a product name. the product will be selected from the table of product management including the other information for that specific product(actual price,stock,selling price) that will be show on the index
add_form.php
<?php
require_once 'dbconfig.php';
if($_POST)
{
$pname = $_POST['pname'];
$gname = $_POST['gname'];
$saledate = $_POST['saledate'];
$quantity = $_POST['quantity'];
$actualprice = $_POST['actualprice'];
$sellprice = $_POST['sellprice'];
$profit = $_POST['profit'];
$carryO = $_POST['carryO'];
$sells = $_POST['sells'];
$expense = $_POST['expense'];
try{
$stmt = $db_con->prepare("INSERT INTO tblsales(pname,gname,saledate,quantity,actualprice,sellprice,carryO,sells,expense,profit)
VALUES(:upname,:ugname,:usaledate,:uquantity,:uactualprice,:usellprice,:ucarryO,:usells,:uexpense,:uprofit)");
$stmt->bindParam(":upname", $pname);
$stmt->bindParam(":ugname", $gname);
$stmt->bindParam(":usaledate", $saledate);
$stmt->bindParam(":uquantity", $quantity);
$stmt->bindParam(":uactualprice", $actualprice);
$stmt->bindParam(":usellprice", $sellprice);
$stmt->bindParam(":ucarryO", $carryO);
$stmt->bindParam(":usells", $sells);
$stmt->bindParam(":uexpense", $expense);
$stmt->bindParam(":uprofit", $profit);
if($stmt->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
<div id="dis">
</div>
<form method='post' id='emp-SaveForm' action="#">
<table class='table table-bordered'>
<tr>
<td>Product Name</td>
<td><input type='text'name='pname' class='form-control' required> </td>
</tr>
<tr>
<td>Guest Name</td>
<td><input type='text' name='gname' class='form-control' required> </td>
</tr>
<tr>
<td>Sale Date</td>
<td><input type='date' name='saledate' class='form-control' required></td>
</tr>
<tr>
<td>Quantity</td>
<td><input type='text' name='quantity' class='form-control' id="quantity" required></td>
</tr>
<tr>
<td>Actual Price</td>
<td>
<input type='text'name ="actualprice" id="aaprice" class='form-control' required></td>
</tr>
<tr>
<td>Selling Price</td>
<td>
<input type='text' name='sellprice' class='form-control' type = "number" id="ssprice" required></td>
</tr>
<tr>
<td>Carry Over</td>
<td><input type='text' name='carryO' class='form-control' required></td>
</tr>
<tr>
<td>Sells</td>
<td><input type='text' name='sells' class='form-control' required></td>
</tr>
<tr>
<td>Expense</td>
<td><input type='text' name='expense' class='form-control' required></td>
</tr>
<tr>
<td>Profit</td>
<td><input name='profit' class='form-control' type = "number" id="profit" required></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
index.php
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Product Name</th> //selected from product management table
<th>Sale Date</th>//(user input)
<th>Quantity</th>//(user input)
<th>Actual Price</th> //price of the selected product on the management table
<th>Selling Price</th> //price of the selected product on the management table
<th>Carry Over</th> //stock from the selected product on the management table
<th>Sells</th>//selling price of the selected product on the management table * quantity(user input)
<th>Expense</th>
<th>Profit</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
if(isset($_POST['months'])){ $months = $_POST['months']; }else { $months='';}
$stmt = $db_con->prepare("SELECT * FROM tblsales WHERE MONTH(saledate) = '".$months."' ");
//this is for the sales management for the monthly view function didn't include the my months select this post already long enough
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['pname']; ?></td>
<td><?php echo $row['saledate']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['actualprice']; ?></td>
<td><?php echo $row['sellprice']; ?></td>
<td><?php echo $row['carryO']?></td>
<td><?php echo $row['sells']?></td>
<td><?php echo $row['expense']?></td>
<td><?php echo $row['profit']; ?></td>
<td align="center">
<a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
Better way by using ajax for this case.
$.ajax({
url: "data.php",//file wich has query select to db table
data: {id:theid},//describe your data here
dataType: 'json',// type of data that will you get (JSON/HTML).
type: 'POST',//sending type (POST/GET)
success: function(data) {
showTable();
}
});
How to split my page into 4 sections with data from database?
I'm displaying data from the database and they appear one by one on the table. And I want to split them into 4 parts and each of them will show another result from the database. In addition, I would like to make line in the middle, which will keep them separated.
That's my code, to show results from DB:
EDIT: Ok, I edited like u said, and now page is splitted on 2 section, but I got on them the same results. How to change this, that on the left side will be shown one record, and on the right side another.
$result = $wpdb->get_results("SELECT company_wojewodztwo, company_powiat, company_miasto, company_name, telefon, company_nip, company_opis FROM test WHERE company_wojewodztwo = '$woj' AND company_powiat = '$pow' AND company_miasto = '$nazwa' ORDER BY RAND()");
foreach ( $result as $k => $v ) {
$c_name = stripslashes($v->company_name);
$c_opis = stripslashes($v->company_opis);
$c_mob_nr = stripslashes($v->telefon);
$c_nip = stripslashes($v->company_nip);
?>
<table>
<tbody>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo $c_name; ?></td>
<td style="width: 50%;"><?php echo $c_name; ?></td>
</tr>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo $c_nip ?></td>
<td style="width: 50%;"><?php echo $c_nip ?></td>
</tr>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo $c_mob_nr ?></td>
<td style="width: 50%;"><?php echo $c_mob_nr ?></td>
</tr>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo $c_opis ?></td>
<td style="width: 50%;"><?php echo $c_opis ?></td>
</tr>
</tbody>
</table>
<?php if(count($result) != $k+1){ ?>
<p>___________________________________________________</p>
<?php } ?>
<?php
}
?>
do something like this:
<table>
<tbody>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo 'data 1'; ?></td>
<td style="width: 50%;"><?php echo 'data 2'; ?></td>
</tr>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo 'data 1'; ?></td>
<td style="width: 50%;"><?php echo 'data 2'; ?></td>
</tr>
</tbody>
</table>
I put styles inline, You try to put them in a css file.
Update your code...
<?php
global $wpdb;
$result = $wpdb->get_results("SELECT company_province, company_district, company_city, company_name, telefon, company_nip, company_opis FROM test WHERE company_province = '$woj' AND company_district = '$pow' AND company_city = '$nazwa' ORDER BY RAND()");
foreach ( $result as $k => $v ) {
$c_name = stripslashes($v['company_name']);
$c_opis = stripslashes($v['company_opis']);
$c_mob_nr = stripslashes($v['telefon']);
$c_nip = stripslashes($v['company_nip']);
?>
<div class="parent">
<table>
<tr><th><p><b> Name: </b></th><td>
<?php echo $c_name;?></p></td></tr>
<tr><th><p><b> NIP: </b></th><td>
<?php echo $c_nip;?></p></td></tr>
<tr><th><b> Number tel: </b></th><td>
<?php echo '+48 '.$c_mob_nr;?><br></td></tr>
<tr><th><b> Opis Firmy: </b></th><td>
<span class="more"> <?php echo $c_opis;?></span></td></tr>
</table>
<?php if(count($result) != $k+1){ ?>
<p>___________________________________________________</p>
<?php } ?>
</div>
<?php
}
?>
I'm trying to delete the selected rows from the list I have in mysql so I won't have to delete the rows in my table one by one. When I press delete, my page refreshes without any php error but I don't get the result desired either. here is what I have:
<?php $product_set = find_all_products(); ?>
<body>
<form action="manage_products.php" method="delete">
<div class="page">
<article>
<div id="page">
<?php echo message(); ?>
<h2>Manage Products</h2>
<table>
<tr>
<th style="text-align: left; width: 125px;">Location</th>
<th style="text-align: left; width: 250px;">URL to the Product</th>
<th style="text-align: left; width: 100px;">First Name</th>
<th style="text-align: left; width: 100px;">Last Name</th>
<th style="text-align: left; width: 100px;">Size</th>
<th style="text-align: left; width: 100px;">Status</th>
<th style="text-align: left; width: 100px;">Checked</th>
<th colspan="2" style="text-align: left;">Actions</th>
</tr>
<?php while($product = mysqli_fetch_assoc($product_set)){ ?>
<tr>
<td><?php echo htmlentities($product["location"]);?></td>
<td><?php echo htmlentities($product["productURL"]); ?></td>
<td><?php echo htmlentities($product["fname"]); ?></td>
<td><?php echo htmlentities($product["lname"]); ?></td>
<td><?php echo htmlentities($product["size"]); ?></td>
<td><?php echo htmlentities($product["status"]); ?></td>
<td><input name="checkbox" type="checkbox" id="checkbox[]" value="<?php echo $product['id']; ?>"></td>
<td>Edit Order</td>
<td>Delete Order</td>
</tr>
<?php } ?>
</table>
<?php
// Check if delete button active, start this
if(isset($_GET['delete']))
{
$checkbox = $_GET['checkbox'];
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM product WHERE link_id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
$_SESSION["message"] = "Product deletion failed.";
redirect_to("created_products.php"); }
}
//mysqli_close($dbc);
?>
<br />
</div>
</div>
<br>
<input type="submit" name="submit" value="Delete" onclick="return val();"/>
</form>
<div class="clear-all"></div>
</article>
</div>
</body>
Also place all the code which is for deleting the rows in the starting of your file. Thank you #Traveller for this.
Instead of for loop, use WHERE IN
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM product WHERE link_id='$del_id'";
$result = mysql_query($sql);
}
Replace that with
$ids = implode(",", $_POST['checkbox']);
$sql = "DELETE FROM product WHERE link_id in ($ids)";