Post table rows which are checked with other select boxes - php

This may be a duplicate question,
But still, I did not find the answer.
My requirement is :
How to get the table rows which are CHECKED.
Here is my issue's screenshot. enter image description here
My checkbox name is 'check[]'
and the name of the select box is 'class[]',
and the form is posted to process.php.
How to get the value of 'class[]' where the checked boxes are checked so that I can then process with PHP-MYSQL?
My code is here:
<div class="col-md-5">
<form action="process.php" method="post">
<table class="table" id="table">
<tr><th>Opt</th><th>Name</th><th>Next Class</th></tr>
<? $q = $sdb->where('ac_CurClass',4)->get('tbl_accounts');
foreach ($q as $r){ ?>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="<?=$r['ac_Id'];?>"></td>
<td><?=ac_details($r['ac_Id'])->ac_Name;?></td>
<td>
<select class="form-control small" name="class[]">
<? $c = $sdb->where('c_Id',ac_details($r['ac_Id'])->ac_CurClass,">")->get("tbl_classes");
foreach($c as $d) {?>
<option value="<?=$d['c_Id'];?>"><?=$d['c_Name'];?></option>
<? } ?></select>
</td>
</tr>
<? } ?>
</table>
<button type="submit" class="btn btn-danger">Update</button>
</form>
</div>

Hope this code is help full for you
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<div class="col-md-5">
<form action="#" method="post">
<table class="table" id="table">
<thead><tr><th>Opt</th><th>Name</th><th>Next Class</th></tr></thead>
<tbody id="cont">
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="1"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="2"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="3"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-danger" id="submit">Update</button>
</form>
</div>
<script>
$(document).ready(function(){
$('#submit').click(function(){
$("#cont input:checkbox:checked").map(function(){
alert('Checkbox value - '+$(this).val()+' / Select Box value - '+$(this).parent().next().next('td').find('select').val());
//alert('Select Box value - '+$(this).parent().next().next('td').find('select').val());
});
});
});
</script>
After that you can pass a Ajax so that only checked rows post.

Try as follows
Post as form
<form action="process.php" method="post">
In process.php file
if($check[0]===true){
$nextclass1 = $_POST['list_box'];
}
if($check[1]===true){
$nextclass2= $_POST['list_box'];
}

Related

Select Array not being sent via $_POST

Here is a small section of my form. It is set up that a user can add information about one munro, or multiple. Hence the use of arrays for input boxes, check boxes and select option boxes.
<fieldset class="row1">
<H2>Munro Details</H2>
<table id="munroTable" class="form" border="0">
<tbody>
<tr>
<td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td>
<td>
<label>Name</label>
<input class = "textbox" type="text" maxlength = "30" required="required" name="name[]">
</td>
<td>
<label>Height (metres)</label>
<input class = "textbox" type="number" maxlength = "5" required="required" name="height[]">
</td>
<td>
<label>Classification</label>
<select name = "classification[]">
<optgroup label="Scottish Hills">
<option value="Munro">Munro</option>
<option value="Corbett">Corbett</option>
<option value="Graham">Graham</option>
<option value="Donald">Donald</option>
</optgroup>
<optgroup label="Non Scottish Hills">
<option value="Furth">Furth</option>
<option value="Hewitt">Hewitt</option>
<option value="Wainwright">Wainwright</option>
<option value="Brikett">Brikett</option>
</optgroup>
<optgroup label="UK wide">
<option value="Marilyn">Marilyn</option>
</optgroup>
</select>
</td>
<td>
<label>Topped?</label>
<input type="checkbox" value = "Yes" name="topped[]" checked="checked">
</td>
</tr>
</tbody>
</table>
<p>
<input class = "myButton" type="button" value="Add Munro" onClick="addRow('munroTable')" />
<input class = "myButton" type="button" value="Remove Munro" onClick="deleteRow('munroTable')" />
</p>
</fieldset>
The issue I'm having is with the select option for "classification".
When I use echo "<br>All data".print_r($_POST); so see what data is being sent sucessfully, the classification doesn't show up.
I'm assuming it is something very simple, but I just can't find it.
Thanks for taking the time to look.

php mysql can't multiply a mysql result and a variable

I can't for the life of me figure out why i keep coming up with 0 on this ... i'm pulling a price from one of my tables and multiplying it by the quantity they are putting in in the form ... for some reason it when i try and do the math, it keeps coming up as 0 ... any help?
code:
$get_code = "SELECT * FROM products WHERE p_code LIKE '%$po_code%'";
$run_code = mysqli_query($con, $get_code);
$row_code = mysqli_fetch_array($run_code);
$count = $_POST['ord_amt'];
$price = $row_code['p_price'];
$sum_total = $price * $count;
form code:
<form action="" method="post">
<?php
include('includes/connection.php');
global $con;
$cust = "SELECT * FROM users WHERE u_id = '".$_SESSION['u_id']."'";
$r_cs = mysqli_query($con, $cust);
$rw_c = mysqli_fetch_array($r_cs);
echo "<input type='hidden' name='c_id' value='".$rw_c['c_id']."'>";
?>
<table id="datatable1" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Product</th>
<th>Distal Opening</th>
<th>Material</th>
<th>Ply</th>
<th>Size</th>
<th>Length</th>
<th>Options</th>
<th>Or Enter Code (If Known)</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select class="form-control" name="prod" id="selectProd" onchange="get_prod(this.value)" required="required">
<?php get_prod_kind() ?>
</select>
</td>
<td>
<select class="form-control" name="opening" id="distOpen" required="required">
<option value="">Select Opening</option>
<option value="1">Rubberized Reinforced</option>
<option value="2">Standard Opening</option>
<option value="">None</option>
</select>
</td>
<td>
<select class="form-control" name='mat' id="selectMat" onchange="get_ply(this.value)" required="required">
</select>
</td>
<td>
<select class="form-control" name="ply" id="plySelect" onchange="get_size(this.value)" required="required">
<option value=""></option>
</select>
</td>
<td>
<select class="form-control" name="size" id="sizeSelect" onchange="get_len(this.value)" required="required">
<option value=""></option>
</select>
</td>
<td>
<select class="form-control" name="length" id="selectLength" required="required">
<option value=""></option>
</select>
</td>
<td>
<select class="form-control" name="opts" required="required">
<option value="">Select Options</option>
<option value="1">Sewn Top (S)</option>
<option value="2">Seal-In-Liner (C)</option>
<option value="">None</option>
</select>
</td>
<td><input class="form-control" type='text' name='cust_code'></td>
<td><input class="form-control" type='text' name='ord_amt' required="required"></td>
</tr>
</tbody>
</table>
<button class="button button-3d button-rounded button-aqua" name="p_order"><i class="icon-repeat"></i>Next Item</button>
<button class="button button-3d button-rounded button-green"><i class="icon-ok"></i>Submit Order</button>
</form>

Passing the id of button to another page

The following is my HTML. I want to pass the name of the dropdownlist(d1and d2) to another survey.php page when the button is clicked.
<!DOCTYPE html>
<head>
<title>Survey</title>
</head>
<body>
<form id="form1" action="survey.php" method="POST">
<table border=1>
<tr>
<td height=" 30" width="200">
Condition of the item received:
<select name="d1">
<option>Select One</option>
<option value="g">Good</option>
<option value="s">bad</option>
<option value="u">Worst</option>
</select>
</td>
<td height=" 30" width="200">
Price of the Item:
<select name="d2">
<option>Select One</option>
<option value="g">Good</option>
<option value="s">bad</option>
<option value="u">Worst</option>
</select>
</td>
</tr>
<tr>
<td align="center" >
<input type="button" name="submit1" value="Submit" />
</td>
</tr>
</table>
</form>
</body>
</html>
Rewrite:
<form id="form1" action="survey.php" method="POST">
<table border=1>
<tr>
<td height=" 30" width="200">
Condition of the item received:
<select name="d1">
<option>Select One</option>
<option value="Good">Good</option>
<option value="bad">bad</option>
<option value="Worst">Worst</option>
</select>
</td>
<td height=" 30" width="200">
Price of the Item:
<select name="d2">
<option>Select One</option>
<option value="Good">Good</option>
<option value="bad">bad</option>
<option value="Worst">Worst</option>
</select>
</td>
</tr>
<tr>
<td align="center" >
<input type="button" name="submit1" value="Submit" />
</td>
</tr>
</table>
</form>
Firstly, instead of: <input type="button" name="submit1" value="Submit" />
Use: <input type="submit" name="submit1" value="Submit" />
<input type="submit"> is what is used to actually send the form.
Secondly, in the body of survey.php:
<?php
echo "You rated ".$_POST['d1']." for condition."
echo "You rated ".$_POST['d2']." for price."
?>
In short:
The $_POST variable in PHP is automatically set to a dictionary containing all the POST parameters.

how to get all value in dropdownlist in php

I have a dropdown where user select some values and moves to other dropdownlist in sorted order by javascript. How can I get the chosen value in second dropdownlist in next page to a PHP variable ?
<form name="Example" action="next.php" method="post">
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td>
<select name="Features" size="9" MULTIPLE>
<option value="2">Row 2</option>
<option value="4">Row 4</option>
<option value="5">Row 5</option>
<option value="6">Row 6</option>
<option value="7">Row 7</option>
<option value="8">Row 8</option>
<option value="9">Row 9</option>
</select>
</td>
<td align="center" valign="middle">
<input type="Button" value=">>" style="width:100px" onClick="SelectMoveRows(document.Example.Features,document.Example.FeatureCodes)">
<br>
<input type="Button" value="<<" style="width:100px" onClick="SelectMoveRows(document.Example.FeatureCodes,document.Example.Features)"><br>
<input type="Button" value=">>>>" style="width:100px" onClick="selectAll(document.Example.Features);SelectMoveRows(document.Example.Features,document.Example.FeatureCodes)"><br>
<input type="Button" value="<<<<" style="width:100px" onClick="selectAll(document.Example.FeatureCodes);SelectMoveRows(document.Example.FeatureCodes,document.Example.Features)">
</td>
<td>
<select name="FeatureCodes[]" id="FeatureCodes" size="9" MULTIPLE>
<option value="1">Row 1</option>
<option value="3">Row 3</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="submit" id="submit" name="submit"></td>
</tr>
</table>
Thanks in advance!!
The value of the selected element in your second form field should be in:
$_POST['FeatureCodes'][0];
If you only have one FeatureCodes form on the page then you can remove the [] from your HTML and access it using $_POST['FeatureCodes'];

How to generate a query string (url) from a form, php or jquery?

I'm trying to generate a specific url from the form below.
There will be a calendar and the date will go into the url.
Also a value from 9 ticket types and quantities of each of those tickets.
So my url will look something like this
https://sales.site.com/?action=quicksale&venueid=1&businessdate=2012-10-05&ticketids=6,8&quantities=1,1
With these values:
action: always "quicksale",
venueid: always "1",
businessdate: the sales date requested; can be either mm-dd-yyyy or yyyy-mm-dd,
ticketids: see chart below,
quantities: in the order the ticketid's are listed.
How would I approach this, and should I use php or jquery? Post or Get.
Should the calendar be Jquery?
Looking for advice, thanks
<form method="post" action="">-->
<div class="quick-book-form-elements">
<table width="255" class="quick-book-table" cellpadding="4">
<tbody>
<tr class="quick-book-days">
<th> </th>
<th><img src="../public/img/1day-small.png" alt="" /></th>
<th><img src="../public/img/2day-small.png" alt="" /></th>
<th class="quick-book-last"><img src="../public/img/3day-small.png" alt="" /></th>
</tr>
<tr class="quick-book-adults">
<th class="quick-book-labels">
Adult
</th>
<td>
<div class="ticket-style-quick-book">
<select class="adult-ticket-select">
<option value="0">0</option>
<option value="1">1</option>
</select>
<span class="quick-book-price">$40/ea</span>
</div>
</td>
<td>
<div class="ticket-style-quick-book">
<select class="adult-ticket-select">
<option value="0">0</option>
<option value="1">1</option>
</select>
<span class="quick-book-price">$50/ea</span>
</div>
</td>
<td class="quick-book-last">
<div class="ticket-style-quick-book">
<select class="adult-ticket-select">
<option value="0">0</option>
<option value="1">1</option>
</select>
<span class="quick-book-price">$60/ea</span>
</div>
</td>
</tr>
<tr class="quick-book-child">
<th class="quick-book-labels">Child</th>
<td>
<div class="ticket-style-quick-book">
<select class="adult-ticket-select">
<option value="0">0</option>
<option value="1">1</option>
</select>
<span class="quick-book-price">$30/ea</span>
</div>
</td>
<td>
<div class="ticket-style-quick-book">
<select class="adult-ticket-select">
<option value="0">0</option>
<option value="1">1</option>
</select>
<span class="quick-book-price">$40/ea</span>
</div>
</td>
<td class="quick-book-last">
<div class="ticket-style-quick-book">
<select class="adult-ticket-select">
<option value="0">0</option>
<option value="1">1</option>
</select>
<span class="quick-book-price">$50/ea</span>
</div>
</td>
</tr>
<tr class="quick-book-family">
<th class="quick-book-labels">Family</th>
<td>
<div class="ticket-style-quick-book">
<select class="adult-ticket-select">
<option value="0">0</option>
<option value="1">1</option>
</select>
<span class="quick-book-price">$125/ea</span>
</div>
</td>
<td>
<div class="ticket-style-quick-book">
<select class="adult-ticket-select">
<option value="0">0</option>
<option value="1">1</option>
</select>
<span class="quick-book-price">$155/ea</span>
</div>
</td>
<td class="quick-book-last">
<div class="ticket-style-quick-book">
<select class="adult-ticket-select">
<option value="0">0</option>
<option value="1">1</option>
</select>
<span class="quick-book-price">$185/ea</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<input type="submit" class="quick-book-submit-btn" name="quick-book-submit-btn" value="" />
</form>
</div><!-- end quick-book-form div -->
For the calendar, indeed you could use the jQuery-ui one. It is a good widget, easy to configure and very powerful.
http://jqueryui.com/demos/datepicker/
You can configure it to put the format you want in the input (YYYY-MM-DD for example)
Finally you should add a listener on the submit event, to perform your action modification:
// This function will be call before the submit
$("#YOUR_FORM_ID").submit(function(submitEvent) {
// Initialize the query param array
var queryParams = [];
// Fill the query param with values
queryParams.push("action=quicksale");
queryParams.push("venueid=1");
queryParams.push("businessdate=" + $("#YOUR_INPUT_DATE_ID").val());
// etc...
// Finally update the form action
$(this).attr('action', 'https://sales.site.com/?' + queryParams.join("&"));
// The action has been updated
// The submit will process
});

Categories