i want 14 records to be uploaded. Before uploading i want to select corresponding check button. At a time only one record can be uploaded. So all 14 records are arranged in a table with two buttons, one for choose file and other for submit. But problem is that only very first document is uploaded, others don't get uploaded. later i knew that i must use more than one form for all submission. how can it possible?
<div class="portal-body" style="min-height: 268px;">
<table class="table striped hover bordered" id="sample_editable_4">
<thead>
<tr>
<th id="eval_style">Sl No.</th>
<th id="eval_style">Document Name</th>
<th id="eval_style">select</th>
<th id="eval_style">Choose</th>
<th id="eval_style">Submit</th>
</tr>
</thead>
<tbody>
<?php $i=1;
foreach($evidence_details->result() as $row_evidence) { ?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $row_evidence->evidence_name; ?> </td>
<td>
<input type="checkbox" name="evidences" id="<?php echo $row_evidence->evidence_id; ?>" value="<?php echo $row_evidence->evidence_id; ?>" <?php if(in_array($row_evidence->evidence_id,$evidence)) { ?>checked="checked"<?php } ?> />
</td>
<td><input type="file" name="multiUpload" id="multiUpload" multiple /></td>
<td><button type="submit" class="btn blue" name="submitHandler" id="submitHandler" style="margin-top: 15px;margin-left: 54px;">Submit</button></td>
</tr>
<?php $i++; } ?>
</tbody>
</table>
</div>
<script type="text/javascript">
var config = {
support : "image/jpg,image/png,image/bmp,image/jpeg,image/gif,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/csv,application/pdf",
form: "demoFiler", // Form ID
dragArea: "dragAndDropFiles",
uploadUrl: "<?php echo base_url(); ?>home/multiple_upload"
}
$(document).ready(function()
{
initMultiUploader(config);
});
</script>
controller
function multiple_upload()
{
$application_id=$this->session->userdata('application_id');
if(!is_dir('./application/assets/uploads/'.$application_id))
{
mkdir('./application/assets/uploads/'.$application_id, 0777, TRUE);
}
if($_SERVER['REQUEST_METHOD'] == "POST"){
if(move_uploaded_file($_FILES['file']['tmp_name'], "./application/assets/uploads/".$application_id."/".$_FILES['file']['name'])){
echo($_POST['index']);
}
exit;
}
}
**multiupload.js**
function initMultiUploader(){
new multiUploader(config);
}
Related
I am buildingd a library management system in PHP and HTMl.
I have some problem with the borrowing system where user can borrow books.
Here is my emitere-carti.php:
<form action="imprumutare.php" method="POST">
<table class="table table-dark">
<thead>
<tr>
<th>Imprumutare</th>
<th scope="col">Titlu </th>
<th scope="col">Autor</th>
<th scope="col">Categorie</th>
<th scope="col">Stoc</th>
</tr>
</thead>
<tbody>
<?php
$selectare="SELECT * FROM carti";
$rezultat=mysqli_query($conn,$selectare);
if(mysqli_num_rows($rezultat)>0){
while($row=mysqli_fetch_assoc($rezultat)){
$carte_nume=$row['titlu'];
$disabled=$row['stoc']>0 ? "" :"disabled";
?>
<tr>
<td><input type="submit" name="test" class="btn btn-secondary"
value="Imprumutare" <?php echo $disabled;?>></input>
<td><input type="text" name="nume" value="<?php echo $row['titlu'];?
>"></input></td>
<td><?php echo $row['autor'];?></td>
<td><?php echo $row['categorie'];?></td>
<td><?php echo $row['stoc'];?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</form>
Here is my imprumutare.php(that means borrowing):
include('conexiune.php');
//sfarsit if
//Imprumutare
if(isset($_POST['test'])){
$id=$_POST['identificator'];
$nume_carte=$_POST['nume'];
$sql_rezervare="UPDATE carti SET stoc=stoc-1 WHERE
titlu='$nume_carte' ";
if( mysqli_query($conn,$sql_rezervare)){
header('location:emitere_carti.php');
}
else{
die(mysqli_error($conn));
}
}
Here is a screenshot about what I am talking:
So my problem is both buttons are decrementeing the same value(the value of stoc).
Can someone help me?
I send the data from the database to the screen with foreach.I do not see any results when I click the button.where do i make mistakes i ask you to help
<table class="table">
<thead class="thead-dark" align="center" >
<th >id</th>
<th >EğitimAdı</th>
<th >Adres</th>
<th >Onay </th>
</thead>
<tbody>
<form id="form1" action="" method="post">
<?php $i=1; foreach($dbb as $ac){ ; ?>
<tr align="center" >
<td > <?php echo $ac[0]; ?> </td>
<td > <?php echo $ac[1]; ?></td>
<td align="center"> <iframe width="360" height="115" src="<?php echo $ac[2]; ?>" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen ></iframe></td>
<td >
<button type="button" value="<?php echo $ac[0]; ?>" id="gonder" onclick="gonder('this.val()')">İzledim</button>
</td>
</tr>
<?php $i++; } ?>
</form> <p></p>
</tbody>
</table>
gonder.js send to the database
function gonder(deger){
$.ajax({
type:"post",
url:"isleme.php",
data:deger,
success:function(cevap) {
$("p").text(cevap);
}
})
}
isleme.php to view the screen
<?php
$b=$_POST['deger'];
echo $b;
?>
First you're missing parentheses:
onclick="gonder" has to be onclick="gonder()"
Secondly variable "deger" is empty because #id doesn't exist, try changing to:
var deger = $("#gonder").val();
I noticed you are iterating and having same id for all the elements. Ideally id should be unique in each of the document.
You can do either of the below:
prepare and have unique id for each iterative element.
Try removing id element since you are not dependent on click using id.
Please let me know, if it helps?
First I will tell what I want to achieve, and then I will explain how I was trying to do it.
I have two tables, one stores type of vessels with a description and their own Id. Then I have another table in wich the vessel type has been stored as text. My goal is to select each one (both records in both tables) with a checkbox in both and store in the table 2 the Id from the table 1.
I will introduce data, to help.
Table 1
1|Balandra|Some description
2|Bergantin|Some description
3|Whatever |Whatever.....
Table2
Balandra
Bergantin
Whatever
Then, I have created a php page that shows both tables with the checkbox I mentioned above. Checkboxes store the Table1 Id and Table2 vesseltypename.
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<a href=<?php echo '../vista/modificar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
pencil"></em></a>
<a href=<?php echo '../datos/borrar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
trash"></em></a>
</td>
<td class="hidden-xs"><?php echo
$navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid" value=<?
php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body paneltodo">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-arrow-circle-o-left"></em>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
So, I want to check both table records and store the table1 Id in the table2 idtypevessel field.
I thought that a php file could store both items and call the update function with those parameters, like this:
<?php
require './modelo.php';
$idnavio = $_GET['agruparid'];
$vessel = $_GET['agruparvessel'];
Any suggestions, because I think I have to do a button to submit this parameters, but it must be working on both tables, and I don't know how to access both foreach loop at the same time.
Thanks in advance.
E. Salas
review bellow reference code to submit multi selected checkbox values
for multi selected checkbox submission you must use [] operator after name attribute in html
index.php
<form action="/checkbox.php" method="post">
<strong>Cars:</strong><br>
<?php
$cars = array("Volvo", "BMW", "Toyota");
$colors = array("Red", "Green", "Black");
foreach($cars as $single){
?>
<input type="checkbox" name="cars[]" value="<?php echo $single; ?>">
<?php
}
<br>
<strong>colors:</strong><br>
foreach($colors as $single){
?>
<input type="checkbox" name="colors[]" value="<?php echo $single; ?>">
<?php
}
?>
<br>
<input type="submit" value="Submit!">
</form>
checkbox.php
<?php
echo "<pre>";
var_dump($_POST);
exit;
In your case:
<form action="/checkbox.php" method="post">
<div class="col-md-6">
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-pencil"></em>
<em class="fa fa-trash"></em>
</td>
<td class="hidden-xs"><?php echo $navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid[]" value=<?php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-arrow-circle-o-left"></em>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel[]" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<input type="submit" value="Submit!">
</form>
Finally I solved this with Javascript. One of my partners helped me, I post this to help people in my situation.
I created a script, here is the code:
<script type="text/javascript">
function cogeNavioDyncoopnet(){
var checkedValueNavioD = null;
var inputElements = document.getElementsByClassName('checknaviod');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValueNavioD = inputElements[i].value;
break;
}
}//return checkedValueNavioD;
var input_nav_dyn = document.getElementById("nav_dyn");
input_nav_dyn.value = checkedValueNavioD;
}
function cogeNavioForSea(){
var checkedValueNavioFs = null;
var inputElements = document.getElementsByClassName('checknaviofs');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValueNavioFs = inputElements[i].value;
break;
}
}//return checkedValueNavioFs;
var input_nav_fs = document.getElementById("nav_fs");
input_nav_fs.value = checkedValueNavioFs;
}
</script>
Then I created a Form below, that collects values and sends them to my .php control file.
<div class="hidden-xs">
<form class="hidden-xs" method="POST"
action="../datos/actualizarnavios.php">
<input id="nav_dyn" type="text" name="idnaviodyncoop">
<input id="nav_fs" type="text" name="navioforsea" >
<input id="botonasignar" type="submit" name="enviardatosdynfs">
</form>
</div>
I hope this helps. Thanks for the feedback, as always.
I have a table with some checkboxes in every row. There is a select element in the table footer with several options. When the user chooses an option, i want to pass the value of any checked checkboxes and the selected option to a php script.
This is the form:
<form name="doall" method="POST" action="action.php">
<table>
<tbody>
<?php for($j=0;$j<count($userToRead);$j++){ ?>
<tr>
<td>
<input type="checkbox" id="selection_<?php echo $j ?>" name="objectSelected[<?php echo $userToRead[$j]['id'] ?>]" value="1"/>
</td>
<td align="center">
<?php echo $userToRead[$j]['id'] ?>
</td>
<td align="center" style="text-align:center;padding-left:15px;background-color:<?php echo $SListsStatus[intval($userToRead[$j]['userstatus'])][1]; ?>;" >
</td>
<td align="center">
<?php echo stripaccenti($userToRead[$j]['user']) ?>
</td>
<td>
<?php echo stripaccenti($SUserType[$userToRead[$j]['type']]['name']) ?>
</td>
<td align="center">
<?php echo stripaccenti($userToRead[$j]['first_name']) ?>
</td>
<td align="center">
<?php echo stripaccenti($userToRead[$j]['last_name']) ?>
</td>
<td align="center">
<?php echo stripaccenti($userToRead[$j]['title']) ?>
</td>
<td class="actBtns">
<a href="#" title="Update" class="tipS">
<img src="images/icons/edit.png" alt="" />
</a>
<a href="#" title="Remove" class="tipS">
<img src="images/icons/remove.png" alt="" />
</a>
</td>
</tr>
<?php } // end for ?>
</tbody>
<tfoot>
<tr>
<td colspan="9">
<div class="itemActions">
<label>Con tutte le selezionate:</label>
<select name="whatDoAll">
<option value="1">Attiva</option>
<option value="2">Disattiva</option>
</select>
<input type="submit" value="Esegui" class="button redB" style="margin: 5px;"/>
</div>
</td>
</tr>
</tfoot>
</table>
</form>
So in every line of my table I have a checkbox where the value is the ID of the db object that I need to modify with my php script.
This is my script:
$('input[type="submit"]').click(function() {
var output = '';
$('input[type="objectSelected"]:checked').each(function(index) {
output += $(this).val() + ", ";
});
alert(output + "is checked!");
});
In the php file i try to retrieve the variable with $_POST['objectSelected'] but the variable is always empty. Also, the script alert is empty.
The tables are create with jquery: if I use a pure html table with pure html checkboxes everything works!
You are doing wrong. You are specifying input type then the code should be:
<script type="text/javascript">
$('input[type="submit"]').click(function() {
var output = '';
$('input[type="checkbox"]:checked').each(function(index) {
output += $(this).val() + ", ";
});
alert(output + "is checked!");
});
</script>
Hope this helps you
I added Edit button to my jQuery Datatable. When the user clicks on this button, the row becomes editable. Updated row should be saved to MySQL DB, but here comes the problem - the updated row is not saved to DB. Firebug does not show any error message. Can someone help me figure out the problem?
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#newspaper-b').dataTable({
"sPaginationType":"full_numbers",
"aaSorting":[[3, "asc"]],
"bJQueryUI":true
});
$(".edit_but").click(function() {
var ID=$(this).attr('id');
$("#first_"+ID).hide();
$("#last_"+ID).hide();
$("#first_input_"+ID).show();
$("#last_input_"+ID).show();
});
$(".edit_tr").change(function() {
var ID=$(this).attr('id');
var first=$("#first_input_"+ID).val();
var last=$("#last_input_"+ID).val();
var dataString = 'flightNum='+ ID +'&from='+first+'&STADate='+last;
$("#first_"+ID).html('<img src="load.gif" />'); // Loading image
if(first.length>0&& last.length>0) {
$.ajax({
type: "POST",
url: "callpage.php?page=tables/edit.php",
data: dataString,
cache: false,
success: function(html) {
$("#first_"+ID).html(first);
$("#last_"+ID).html(last);
}
});
} else
{
alert('All fields must be filled out.');
}
});
// Edit input box click action
$(".editbox").mouseup(function() {
return false
});
// Outside click action
$(document).mouseup(function() {
$(".editbox").hide();
$(".text").show();
});
$("tr").click(function(){
$(this).addClass("selected").siblings().removeClass("selected");
});
});
</script>
<table id="newspaper-b" border="0" cellspacing="2" cellpadding="2" width = "100%">
<thead>
<tr>
<th scope="col">Flt Num</th>
<th scope="col">From</th>
<th scope="col">STA Date</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php foreach ($result1 as $row):
$flightNum=$row['flightNum'];
$from=$row['frm'];
$STADate=$row['STADate'];
?>
<tr id="<?php echo $flightNum; ?>" class="edit_tr">
<td><?php echo $row['flightNum'];?></td>
<td class="edit_td">
<span id="first_<?php echo $flightNum; ?>" class="text">
<?php echo $from;?>
</span>
<input type="text" value="<?php echo $from;?>"
class="editbox" id="first_input_<?php echo $flightNum; ?>"/>
</td>
<td class="edit_td">
<span id="last_<?php echo $flightNum; ?>" class="text">
<?php echo $STADate; ?>
</span>
<input type="text" value="<?php echo $STADate; ?>"
class="editbox" id="last_input_<?php echo $flightNum; ?>"/>
</td>
<td class="edit_td"><?php echo $row['pkID']; ?></td>
<td id="<?php echo $flightNum; ?>" class="edit_but">
<div>
<img src='images/edit.png' alt='Edit' />
</div>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
edit.php
<?php
include_once 'include/DatabaseConnector.php';
if(isset($_POST['flightNum'])) {
$flightnum=$_POST['flightNum'];
$from=$_POST['from'];
$STADate=$_POST['STADate'];
$query = 'UPDATE flightschedule
SET frm="'.$from.'",STADate="'.$STADate.'"
WHERE flightNum="'.$flightNum.'"';
DatabaseConnector::ExecuteQuery($query);
echo '1';
} else {
echo '0';
}
?>
Try $(".edit_tr input").change() as the trigger.
Change events are limited to inputs, selects and textareas only, but you've tried binding it to a table row. The code above will bind it to any inputs inside the row with the class.