I have a foreach loop providing data to a html table. I have added a form around the table and on each row am adding an input/checkbox with the value set as the row_id from the db call.
When clicking on the first checkbox it selects, when clicking on other rows the 1st checkbox in the table selects not the row you intended.
I was under the impression that setting the name="whatever[]" like so adds the checkbox to an array? So in the form processor I can get it via $_POST['checkbox'] array. Which is working on the form processor part.
I am using bootstrap to style everything so this might be an issue?
I can't for the life of me seem to be able to fix the click one checkbox get only the first checked.
This is my table code:
<form action="<?php echo URLROOT.'/admin/voyage/sendemail'; ?>" method="POST">
<table id="volunteers" class="table table-bordered text-secondary">
<thead class="bg-msp-lightgrey">
<tr>
<th width="35px">
</th>
<th>
Volunteer
</th>
<th>
Position
</th>
<th>
DBS Status
</th>
<th>
Last Training
</th>
<th>
Last Refit
</th>
<th>
Contact
</th>
<th>
Form
</th>
</tr>
</thead>
<tbody>
<?php foreach ($data['volunteerData'] as $volunteer) : ?>
<?php
$result = 'DBS Form to be sent';
$order = 0;
if ($volunteer->volunteer_dbsSent) {
$result = 'DBS Form sent to volunteer - '.date('d/m/Y', strtotime($volunteer->volunteer_dbsSent));
$order = 1;
}
if ($volunteer->volunteer_dbsReceived) {
$result = 'DBS Form returned to us - '.date('d/m/Y', strtotime($volunteer->volunteer_dbsReceived));
$order = 2;
}
if ($volunteer->volunteer_dbsASTO) {
$result = 'DBS Form sent to ASTO - '.date('d/m/Y', strtotime($volunteer->volunteer_dbsASTO));
$order = 3;
}
if ($volunteer->volunteer_dbsReturned) {
$result = 'DBS returned - '.date('d/m/Y', strtotime($volunteer_dbsReturned));
$order = 4;
}
if ($volunteer->volunteer_dbsClear) {
$result = 'DBS clear, cert number: - '.$volunteer->volunteer_dbsCertNum;
$order = 5;
}
?>
<tr>
<td>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="check" name="check[]" value="<?php echo $volunteer->volunteer_id; ?>" />
<label class="custom-control-label" for="check"></label>
</div>
</td>
<td>
<a class="text-msp-lightblue" href="<?php echo URLROOT.'/admin/volunteer/manage/'.$volunteer->volunteer_id; ?>"><?php echo $volunteer->volunteer_firstName.' '.$volunteer->volunteer_lastName; ?></a>
</td>
<td>
<?php echo $volunteer->volunteer_rank; ?>
</td>
<td data-sort="<?php echo $order; ?>">
<?php echo $result; ?>
</td>
<td>
</td>
<td>
</td>
<td>
<a class="text-msp-lightblue" href="mailto:<?php echo $volunteer->volunteer_email; ?>"><?php echo $volunteer->volunteer_email; ?></a><br />
<a class="text-msp-lightblue" href="tel:<?php echo $volunteer->volunteer_mobile; ?>"><?php echo $volunteer->volunteer_mobile; ?></a>
</td>
<td>
<a target="_blank" class="text-msp-lightblue" href="<?php echo URLROOT.'/admin/volunteer/volunteerForm/'.$volunteer->volunteer_id; ?>">View</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="row mt-4">
<div class="col-5">
<div class="input-group">
<select class="custom-select" id="email" name="email">
<option selected>Update DBS Status...</option>
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select>
<div class="input-group-append">
<button class="btn btn-msp-lightblue text-white" type="submit"><i class="fas fa-paper-plane"></i> Send</button>
</div>
</div>
</div>
</div>
</form>
Try this code. Added new variable $type= ""; and passed in checkbox array.
<input type="checkbox" class="custom-control-input" id="check_<?php echo $Inc;?>" name="check[<?php echo $type;?>][]" value="<?php echo $volunteer->volunteer_id; ?>" />
Checkbox Id also made unique.
<tbody>
<?php
$Inc = 1;
foreach ($data['volunteerData'] as $volunteer) : ?>
<?php
$result = 'DBS Form to be sent';
$order = 0;
$type= "";
if ($volunteer->volunteer_dbsSent) {
$result = 'DBS Form sent to volunteer - '.date('d/m/Y', strtotime($volunteer->volunteer_dbsSent));
$order = 1;
$type= "dbsSent";
}
if ($volunteer->volunteer_dbsReceived) {
$result = 'DBS Form returned to us - '.date('d/m/Y', strtotime($volunteer->volunteer_dbsReceived));
$order = 2;
$type= "dbsReceived";
}
if ($volunteer->volunteer_dbsASTO) {
$result = 'DBS Form sent to ASTO - '.date('d/m/Y', strtotime($volunteer->volunteer_dbsASTO));
$order = 3;
$type= "dbsASTO";
}
if ($volunteer->volunteer_dbsReturned) {
$result = 'DBS returned - '.date('d/m/Y', strtotime($volunteer_dbsReturned));
$order = 4;
$type= "dbsReturned";
}
if ($volunteer->volunteer_dbsClear) {
$result = 'DBS clear, cert number: - '.$volunteer->volunteer_dbsCertNum;
$order = 5;
$type= "dbsClear";
}
?>
<tr>
<td>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="check_<?php echo $Inc;?>" name="check[<?php echo $type;?>][]" value="<?php echo $volunteer->volunteer_id; ?>" />
<label class="custom-control-label" for="check"></label>
</div>
</td>
<td>
<a class="text-msp-lightblue" href="<?php echo URLROOT.'/admin/volunteer/manage/'.$volunteer->volunteer_id; ?>"><?php echo $volunteer->volunteer_firstName.' '.$volunteer->volunteer_lastName; ?></a>
</td>
<td>
<?php echo $volunteer->volunteer_rank; ?>
</td>
<td data-sort="<?php echo $order; ?>">
<?php echo $result; ?>
</td>
<td>
</td>
<td>
</td>
<td>
<a class="text-msp-lightblue" href="mailto:<?php echo $volunteer->volunteer_email; ?>"><?php echo $volunteer->volunteer_email; ?></a><br />
<a class="text-msp-lightblue" href="tel:<?php echo $volunteer->volunteer_mobile; ?>"><?php echo $volunteer->volunteer_mobile; ?></a>
</td>
<td>
<a target="_blank" class="text-msp-lightblue" href="<?php echo URLROOT.'/admin/volunteer/volunteerForm/'.$volunteer->volunteer_id; ?>">View</a>
</td>
</tr>
<?php
$Inc++;
endforeach; ?>
</tbody>
Related
how to insert select option value in database using checkbox?When I click checkbox and click enroll button ,select option doesn't inserting selected value.I have 3 options(Regular,Retake,Recourse) in "examtype" table but when I choose more than one subject select option not working perfectly. Here is my code...
here is my select option image
<?php
if (isset($_POST['enroll']))
{
if (!empty($_POST['chk1']))
{
if (isset($_POST['et']))
{
$roll_no = $_SESSION['roll_no'];
//$selectbox1 = $_POST['et'];
foreach($_POST['chk1'] as $checkbox1)
{
foreach($_POST['et'] as $selectbox1)
//for($i=0;$i<sizeof($selectbox1);$i++)
$values = explode("|" , $checkbox1);
$values1= explode("|" , $selectbox1);
$course_id= $values[0];
$semester= $values[1];
$course_name= $values[2];
$selectbox1=$values1[0];
$sql="INSERT INTO pendingcourse(roll_no,course_id,semester,course_name,exam_type,status) VALUES('$roll_no','$course_id','$semester','$course_name','$selectbox1',0)";
$stmt = $connect->prepare($sql);
$stmt->execute();
$checkbox1='';
$selectbox1='';
}
header("location:coursetable.php");
}
}
}
?>
<form action="coursetable.php" method="post" enctype="multipart/form-data">
<div class="container mt-3" >
<div class="accordion mb-4" id="accordionExample" >
<div class="accordion-item" style="background-color: rgb(0, 225, 255);">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button collapsed fw-bold" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne" style="background: #AAFFA9;">
1st Semester
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" >
<div class="accordion-body">
<table class="table table-bordered border-primary text-center">
<thead>
<tr>
<th scope="col-1">Course Id</th>
<th scope="col-1">Semester</th>
<th scope="col-7">Course</th>
<th scope="col-1">Exam Type</th>
<th scope="col-1">Select</th>
<th scope="col-2">Result</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $connect->query("SELECT course_id,semester,course_name FROM coursetable Where semester = '1st' ");
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($rows as $row)
{
$course_id = $row['course_id'];
$semester = $row['semester'];
$course_name = $row['course_name'];
?>
<tr>
<td scope="row"> <?php echo $course_id?></td>
<td > <?php echo $semester ?></td>
<td ><?php echo $course_name ?></td>
<td>
<select name="et[]" class="form-select form-select-sm" aria-label=".form-select-sm example">
<?php
$stmt1 = $connect->query("SELECT * from examtype");
$rows1 = $stmt1->fetchAll(PDO::FETCH_ASSOC);
foreach($rows1 as $row1) {
?>
<option value="<?php echo $row1['exam_type']; ?>"><?php echo $row1['exam_type']; ?></option>
<?php
}
?>
</select>
</td>
<td>
<input type="checkbox" name="chk1[]" value="<?php echo $row['course_id']?>|<?php echo $row['semester']?>|<?php echo $row['course_name']?>|<?php echo $row1['exam_type']?>">
<label class="form-check-label" for="flexCheckDefault">
</label>
</td>
<td></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-2 col-xs-6 offset-md-5 mb-3">
<button type="submit" name="enroll" class="btn btn-warning mt-2">Enroll</button>
</div>
</div>
</div>
</form>
Place the input field inside a form and add
enctype="multipart/form-data"
<select name="et[]" class="form-select form-select-sm" aria-label=".form-select-sm example" multiple>
try this
add multiple in select
SOLVED:
<?php
if (isset($_POST['enroll']))
{
if (!empty($_POST['chk1']))
{
if (!empty($_POST['et']))
{
$roll_no = $_SESSION['roll_no'];
$selectbox1 = $_POST['et'];
$selectbox11=implode(',',array_filter($selectbox1));
$i=0;
foreach($_POST['chk1'] as $checkbox1)
{
$selectbox111 = array_diff(explode(",", $selectbox11),array(""));
$selectbox1111 = $selectbox111[$i];
$values = explode("|" , $checkbox1);
$course_id= $values[0];
$semester= $values[1];
$course_name= $values[2];
$sql="INSERT INTO pendingcourse(roll_no,course_id,semester,course_name,exam_type,status) VALUES('$roll_no','$course_id','$semester','$course_name','$selectbox1111',0)";
$stmt = $connect->prepare($sql);
$stmt->execute();
$checkbox1='';
$i++;
}
}
}
}
?>
I have popup it works normal i need to use method post to get my value from the input balise but the problem is when i do form the popup window displays in just a second then hide again and I need to click two time becausethe first time i got just the last result
<div class="List_modify">
<table class="list">
<thead class="topBar">
<tr>
<th>Prenom</th>
<th>Nom</th>
<th>CIN</th>
<th>Emails</th>
<th>Références</th>
<th>Photos</th>
<th>Niveau</th>
<th class="button_editer" style="vertical-align:middle"><span>Editer</span></th>
</tr>
</thead>
<?php $requet = "select * from Etudiants";
$resultat = mysqli_query($connecte, $requet);
while ($r = mysqli_fetch_array($resultat)) {
?>
<tbody class="container">
<tr>
<td>
<?php echo $r['Prenom']; ?>
</td>
<td>
<?php echo $r['Nom']; ?>
</td>
<td>
<?php echo $r['CIN']; ?>
</td>
<td>
<?php echo $r['Emails']; ?>
</td>
<td>
<?php echo $r['Matricule']; ?>
</td>
<td> <img src="image/<?php echo $r['Photo']; ?> " style="width: 150px; height:150px;"></td>
<td>
<?php echo $r['Niveau']; ?> </td>
<td>
<form method="POST" action="">
<input type="hidden" name="id" value="<?php echo $r['Id_Etudiant']; ?>">
<button class=" button" onclick="show()" style="vertical-align:middle" type="submit" name="submit"><span>Editer<i class=" fas fa-user-edit"></i></span>
</button>
</form>
</td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
<div class="background_page_modify" id="page_modify" onclick="hide()">
<div class="page_etudiant" onclick="event.stopPropagation()">
<div class="closebtn" id="closebtn" onclick="hide()">
<div class="circle"> +</div>
</div>
<div class="etudiant_box">
<?php
if (isset($_REQUEST['submit'])) {
$checkid = $_REQUEST['id'];
echo $checkid;
}
?>
</div>
</div>
</div>
I'm trying to work out how to update my shopping cart without updating other products. Should I be working with sessions here or not? MY current issue is that whenever I change the quantity it updates the other products as well and sets the quantity in the box back to 1. How would I go about changing this?
This is what I currently have, I understand why it updates all the products but I can't figure out how to do it otherwise.
<?php
session_start();
include("header.php");
include_once("dbconnect.php");
include("functies.php");
if (empty($_SESSION['cart'])) {
echo "U heeft geen producten in uw winkelwagen";
} else {
$items = $_SESSION['cart'];
$cartitems = explode(",", $items);
?>
<div align="center">
<?php titel(); ?>
<h1 Winkelwagen <h1>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-10 col-md-offset-1">
<table class="table table-hover">
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th class="text-center">Price</th>
<th class="text-center">Total</th>
<th> </th>
</tr>
</thead>
<tbody>
<?php
$total = 0;
$i=1;
foreach ($cartitems as $key=>$id) {
$sql = "SELECT * FROM products WHERE id = $id";
$res=mysqli_query($conn, $sql);
$r = mysqli_fetch_assoc($res);
$sqlb = "SELECT * FROM brewery WHERE code = $r[brewery_code]";
$resb=mysqli_query($conn, $sqlb);
$rb = mysqli_fetch_assoc($resb);
if (isset($_POST['submit'])) {
$amount = $_POST['amount'];
} else $amount = 1;
?>
<tr>
<td class="col-sm-8 col-md-6">
<div class="media">
<img class="thumbnail pull-left" src="Images/<?php echo $r['name'] ?>.jpg" width="85" height="152" alt="..." >
<div class="media-body">
<h4 class="media-heading"><?php echo $r['name']; ?></h4>
<h5 class="media-heading"> by <?php echo $rb['name'];; ?></a></h5>
<span>Status: </span><span class="text-success"><strong>In Stock</strong></span>
</div>
</div></td>
<td class="col-sm-1 col-md-1" style="text-align: center">
<form action="" method="post">
<input type="number" class="form-control" name="amount" value="1" min="1">
<input type="submit" name="submit" class="btn btn-primary btn-sm">
</form>
</td>
<?php
$total = $total + $r['price'];
$i++;
$producttotal = $amount * $r['price'];
?>
<td class="col-sm-1 col-md-1 text-center"><strong>€ <?php echo number_format($r['price'],2);?> </strong></td>
<td class="col-sm-1 col-md-1 text-center"><strong>€ <?php echo number_format($producttotal,2);?> </strong></td>
<td class="col-sm-1 col-md-1">
<button type="button" class="btn btn-danger">
Verwijderen
</button></td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><h5>Subtotal<br>Estimated shipping</h5><h3>Total</h3></td>
<td class="text-right"><h5><strong>$24.59<br>$6.94</strong></h5><h3>$31.53</h3></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>
<button type="button" class="btn btn-primary"> Continue Shopping </button></td>
<td>
<button type="button" class="btn btn-primary"> Checkout </button>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<?php } ?>
Your form needs to contain an indicator for which product you want to increase the quantity. For example, like this:
<form action="" method="post">
<input type="number" class="form-control" name="amount[<?php echo $id;?>]" value="1" min="1">
<input type="submit" name="submit" class="btn btn-primary btn-sm">
</form>
You can then evaluate the id like this:
if (isset($_POST['submit']) && isset($_POST['amount'][$id])) {
$amount = $_POST['amount'][$id];
} else {
$amount = 1;
}
I don't understand why you would set the amount to 1 if it hasn't be set in the $_POST. I think you have to store the amount per product in the session, not just the ids as you are doing now.
Maybe like this:
if (isset($_POST['submit']) && isset($_POST['amount'][$id])) {
$amount = intval($_POST['amount'][$id]);
} else {
if(isset($_SESSION['amounts'][$id])) {
$amount = $_SESSION['amounts'][$id];
} else {
$amount = 1;
}
}
if(!isset($_SESSION['amounts'])) $_SESSION['amounts'] = array();
$_SESSION['amounts'][$id] = $amount;
When I go to this page It's already search the blank string in the variable before pick the value in option. I just want to search the value when the button is click not automatically search when the user go to this page. And Also there's a problem on my "asc" in query.
If I go to this page. It's already search and show up the blank values
Already Search the Blank
And I insert this code $asc but as you can see in the picture it shows up an error but If I pick in the select option the error will vanish and show the value.
this Ascending to Descending
Please Enter Details Below
<div class="nice" style=" width:20%; margin-left:10%; z-index:100px;">
<div class="control-group">
<label class="control-label" for="inputPassword">Search Catalog:</label>
<div class="controls">
<select name="catalogs">
<option></option>
<?php $result = mysqli_query($dbcon,"select * from book_catalog")or die(mysqli_error());
while ($row=mysqli_fetch_array($result)){ ?>
<option value="<?php echo $row['catalog']; ?>"><?php echo $row['catalog']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Author:</label>
<div class="controls">
<select name="status">
<option></option>
<option>Local</option>
<option>Foreign</option>
</select>
</div>
</div>
<div class="control-group" style="margin-left:210%; margin-top:-150px;">
<label class="control-label" for="inputPassword">Ascending-Descending</label>
<div class="controls">
<select name="asc" >
<option></option>
<option value="acc_id">Accession Number</option>
<option value="author">Author</option>
<option value="book_title">Book Title</option>
<option value="publisher_name">Publisher Name</option>
<option value="copyright_year">Copyright Year</option>
<option value="date_added">Date Added</option>
</select>
</div>
</div>
</div>
<input type="submit" name="submit" value="Search" style="margin-left:43%; margin-top:10%;" /> <br>
</form>
</div>
<?php
$selected_stat = "";
$selected_val = "";
$asc =""; // Storing Selected Value In Variable
if(isset($_POST['submit'])){
$selected_val = $_POST['status'];
$selected_stat = $_POST['catalogs'];
$asc = $_POST['asc']; // Storing Selected Value In Variable
}
?>
<br>
<thead>
<tr>
<th>Acc No.</th>
<th>Call Number</th>
<th>Author</th>
<th>Author Category</th>
<th>Book Title</th>
<th>Category</th>
<th>Book Copies</th>
<th>Publisher Name</th>
<th>Copyright Year</th>
<th>Date Added</th>
<th class="action">Action</th>
</tr>
</thead>
<tbody>
<?php $user_query=mysqli_query($dbcon,"select * from book where catalog = '$selected_stat' OR status = '$selected_val' ORDER BY book.$asc ASC")or die(mysqli_error($dbcon));
while($row=mysqli_fetch_array($user_query)){
$id=$row['book_id'];
?>
<tr class="del<?php echo $id ?>">
<td><?php echo $row['acc_id']; ?></td>
<td><?php echo $row['callnum']; ?></td>
<td><?php echo $row['author']; ?> </td>
<td><?php echo $row['status']; ?></td>
<td><?php echo $row['book_title']; ?> </div></td>
<td><?php echo $row ['catalog']; ?> </td>
<td class="action"><?php echo $row['book_copies']; ?> </td>
<td><?php echo $row['publisher_name']; ?></td>
<td><?php echo $row['copyright_year']; ?></td>
<td><?php echo $row['date_added']; ?></td>
<?php include('toolttip_edit_delete.php'); ?>
<td class="action">
<a rel="tooltip" title="Delete" id="<?php echo $id; ?>" href="#delete_book<?php echo $id; ?>" data-toggle="modal" class="btn btn-danger"><i class="icon-trash icon-large"></i></a>
<?php include('delete_book_modal.php'); ?>
<a rel="tooltip" title="Edit" id="e<?php echo $id; ?>" href="edit_book.php<?php echo '?id='.$id; ?>" class="btn btn-success"><i class="icon-pencil icon-large"></i></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
Sorry for my bad english
When the SQL statement throws an error the best thing to do is log it or dump it to the screen so you can see it as actual SQL. Given the form of the statement I would think that $asc isn't what you think it is, it could possibly even be blank giving:
ORDER BY book. ASC
The book. being something the database can't deal with.
I think the issue with the page running a query automatically on load is because you are calling the query directly in your select element
<select name="catalogs">
<option></option>
<?php $result = mysqli_query($dbcon,"select * from book_catalog")or die(mysqli_error());
while ($row=mysqli_fetch_array($result)){ ?>
<option value="<?php echo $row['catalog']; ?>"><?php echo $row['catalog']; ?></option>
<?php } ?>
</select>
That PHP code isn't waiting for user input, it's just running immediately.
Make your query like this
mysqli_query($dbcon,"select * from book where catalog = '" . $selected_stat ."' OR status = '" . $selected_val ."' ORDER BY book." . $asc . " ASC")or die(mysqli_error($dbcon));
Shown in the image above, I have two entries on my stock_transfer table.
As an example, I will insert two different values to show you that it's working. (5 stocks on Product 1 and 10 stocks on Product 2)
Now, when I try to insert the stocks requested remaining on Product 1 and leave the Product 2, it will be successful.
Here comes the problem. When I try to insert value (290 stocks) on my Product 2, it will insert the value in the Product 1 table.
Can anyone help me with this? Here's my query code:
if (isset($_POST['addCart']) && $_POST['addCart']=="Confirm Stock Transfer") {
foreach($_POST['qtyBuy'] as $index=>$value){
if($value > 0){
$cartProd_id = $_POST['product_id'][$index];
$cartProd_name = $_POST['product_name'][$index];
$cartProd_date = $_POST['product_exp'][$index];
$cartProd_desc = $_POST['product_desc'][$index];
$cartProd_transid = $_POST['transfer_id'][$index];
//Update stock_transfer requests
$update_stock = "UPDATE stock_transfer SET stocks_transferred = stocks_transferred + $value WHERE transfer_id = $cartProd_transid;";
$update_stockE = mysqli_query($connection, $update_stock);
Here's is my code:
<table class="table table-striped table-bordered table-hover results table-fixed table-condensed" id="example">
<thead>
<tr>
<th>#</th>
<th>Product Name</th>
<th>Description</th>
<th>Sell Price</th>
<th>Expiry Date</th>
<th>Instock</th>
<th>Stocks Requested Remaining</th>
<th>Stocks Transferred</th>
<th>Quantity to Transfer</th>
</tr>
</thead>
<tbody>
<?php
$getReq = "SELECT * FROM stock_transfer INNER JOIN td_products ON stock_transfer.transfer_product_id = td_products.product_id WHERE stock_transfer.transfer_number = $tid AND stock_transfer.transfer_tobranch = '$capitalPrefix';";
$getReqE = mysqli_query($connection, $getReq);
while ($row = mysqli_fetch_array($getReqE)) {
$transfer_id = $row['transfer_id'];
$transfer_number = $row['transfer_number'];
$transfer_status = $row['transfer_status'];
$transfer_frombranch = $row['transfer_frombranch'];
$transfer_tobranch = $row['transfer_tobranch'];
$transfer_product_id = $row['transfer_product_id'];
$transfer_quantity = $row['transfer_quantity'];
$transfer_date = $row['transfer_date'];
$stocks_transferred = $row['stocks_transferred'];
$remainingStocks = $transfer_quantity - $stocks_transferred;
$product_id = $row['product_id'];
$product_name = $row['product_name'];
$product_price = $row['sell_price'];
$description = $row['description'];
$quantity = $row['quantity'];
$expiry_date = $row['expiry_date'];
echo $transfer_id;
?>
<tr>
<td class="text-center"><?php echo $product_id; ?>
<input type="hidden" name="product_id[]" value="<?php echo $product_id; ?>">
</td>
<input type="hidden" name="transfer_id[]" value="<?php echo $transfer_id; ?>">
<td><?php echo $product_name; ?>
<input type="hidden" name="product_name[]" value="<?php echo $product_name; ?>">
</td>
<td><?php echo $description; ?>
<input type="hidden" name="product_desc[]" value="<?php echo $description; ?>">
</td>
<td>₱ <?php echo number_format($product_price, 2); ?></td>
<td><?php echo $expiry_date; ?>
<input type="hidden" name="product_exp[]" value="<?php echo $expiry_date; ?>">
</td>
<td><strong><?php echo $quantity; ?></strong></td>
<td><?php echo $remainingStocks; ?></td>
<td><?php echo $stocks_transferred; ?></td>
<td>
<?php if (!$remainingStocks == 0){ ?>
<input type="number" name="qtyBuy[]" id="<?php echo "qtyBuy" . $b++; ?>" min="1" max="<?php echo $remainingStocks;?>">
<?php } else{ ?>
<i class="glyphicon glyphicon-check"></i> Completed
<?php } ?>
</td>
</tr>
<?php }?>
</tbody>
</table>
<div class="form-group">
<input type="submit" name="addCart" value="Confirm Stock Transfer" class="btn btn-info pull-right">
Back to Request List
</div>
Tags
Here's my schema:
See this:
<td>
<input type="number" name="qtyBuy[]" id="<?php echo "qtyBuy" . $b++; ?>" min="1" max="<?php echo $remainingStocks;?>" <?php echo ($remainingStocks == 0') ? 'Disabled=true' : '';?> value="0">
</td>
for security issues, I advise you to use ajax and submit just the qty input for one row each time:
<table class="table table-striped table-bordered table-hover results table-fixed table-condensed" id="example">
<thead>
<tr>
<th>#</th>
<th>Product Name</th>
<th>Description</th>
<th>Sell Price</th>
<th>Expiry Date</th>
<th>Instock</th>
<th>Stocks Requested Remaining</th>
<th>Stocks Transferred</th>
<th>Quantity to Transfer</th>
</tr>
</thead>
<tbody>
<?php
$getReq = "SELECT * FROM stock_transfer INNER JOIN td_products ON stock_transfer.transfer_product_id = td_products.product_id WHERE stock_transfer.transfer_number = $tid AND stock_transfer.transfer_tobranch = '$capitalPrefix';";
$getReqE = mysqli_query($connection, $getReq);
while ($row = mysqli_fetch_array($getReqE)) {
$transfer_id = $row['transfer_id'];
$transfer_number = $row['transfer_number'];
$transfer_status = $row['transfer_status'];
$transfer_frombranch = $row['transfer_frombranch'];
$transfer_tobranch = $row['transfer_tobranch'];
$transfer_product_id = $row['transfer_product_id'];
$transfer_quantity = $row['transfer_quantity'];
$transfer_date = $row['transfer_date'];
$stocks_transferred = $row['stocks_transferred'];
$remainingStocks = $transfer_quantity - $stocks_transferred;
$product_id = $row['product_id'];
$product_name = $row['product_name'];
$product_price = $row['sell_price'];
$description = $row['description'];
$quantity = $row['quantity'];
$expiry_date = $row['expiry_date'];
echo $transfer_id;
?>
<tr>
<td class="text-center"><?php echo $product_id; ?>
</td>
<td><?php echo $product_name; ?>
</td>
<td><?php echo $description; ?>
</td>
<td>₱ <?php echo number_format($product_price, 2); ?></td>
<td><?php echo $expiry_date; ?>
</td>
<td><strong><?php echo $quantity; ?></strong></td>
<td><?php echo $remainingStocks; ?></td>
<td><?php echo $stocks_transferred; ?></td>
<td>
<?php if (!$remainingStocks == 0){ ?>
<input type="number" name="qtyBuy[]" id="qty_buy_<?= $transfer_id ?>" min="1" max="<?php echo $remainingStocks;?>"><a class="btn btn-sm add_qty" data-id="<?= $transfer_id ?>"></a>
<?php } else{ ?>
<i class="glyphicon glyphicon-check"></i> Completed
<?php } ?>
</td>
</tr>
<?php }?>
</tbody>
</table>
<div class="form-group">
<input type="submit" name="addCart" value="Confirm Stock Transfer" class="btn btn-info pull-right">
Back to Request List
</div>
<script>
$(function() {
$('.add_qty').click(function() {
var id = $(this).data('id');
var qty = $("#qty_buy_"+id).val();
$.ajax({
type: 'GET',
url:'/your_action',
data: {id : id, qty : qty},
dataType: 'JSON',
}).done(function(json){
// code to update the values in your row
});
});
});
</script>
The problem was on the
<?php if (!$remainingStocks == 0){ ?>
<input type="number" name="qtyBuy[]" id="<?php echo "qtyBuy" . $b++; ?>" min="1" max="<?php echo $remainingStocks;?>">
<?php } else{ ?>
<i class="glyphicon glyphicon-check"></i> Completed
<?php } ?>
I think the problem is with your input names. You have assigned arrays as names of your inputs. Try to make them unique using the product id.