I am newbie in php as well as bootstrap. I am trying to create master-detail form to receive product from supplier. I had somehow manage to build the format but have difficulties on cloning table row with php select box. My HTML codes are below ...
<div class="form-group">
<div class='row'>
<div class='col-xs-1 col-sm-1 col-md-1 col-lg-1'> </div>
<div class='col-xs-10 col-sm-10 col-md-10 col-lg-10'>
<table class="table table-bordered table-hover" id="table-data">
<thead>
<tr>
<th width="2%"><input id="check_all" class="formcontrol" type="checkbox"/></th>
<th width="38%">Parts Name</th>
<th width="15%">Price</th>
<th width="15%">Quantity</th>
<th width="15%">Total</th>
</tr>
</thead>
<tbody>
<tr id="id1" class="tr_clone">
<td><input class="case" type="checkbox"/></td>
<td>
<div class="dropdown">
<select data-type="partsCode" name="partsNo[]" id="partsNo1" class="form-control">
<?php
$query = "SELECT PARTS_ID, PARTS_NAME FROM parts_info ORDER BY PARTS_NAME";
if ($result = mysqli_query($con, $query))
{
while ($row = mysqli_fetch_array($result))
{
?>
<option value=<?php echo $row['PARTS_ID']; if ($shopid == $row['PARTS_ID']) echo " selected"; ?>> <?php echo $row['PARTS_NAME']; ?> </option>
<?php
}
}
mysqli_free_result($result);
?>
</select>
</div>
</td>
<td><input type="number" name="price[]" id="price1" class="form-control changesNo" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
<td><input type="number" name="quantity[]" id="quantity1" class="form-control changesNo" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
<td><input type="number" name="total[]" id="total1" class="form-control totalLinePrice" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
</tr>
</tbody>
</table>
</div>
<div class='col-xs-1 col-sm-1 col-md-1 col-lg-1'> </div>
</div>
<div class='row'>
<div class='col-xs-1 col-sm-1 col-md-1 col-lg-1'> </div>
<div class='col-xs-12 col-sm-3 col-md-3 col-lg-3'>
<button class="btn btn-danger" type="button">- Delete</button>
<button class="btn btn-success" type="button">+ Add More</button>
</div>
<div class='col-md-3 col-md-offset-4'>
<button class="btn btn-primary btn-block" id="button" type="submit" name="submit" value="Submit">Save</button>
</div>
<div class='col-xs-1 col-sm-1 col-md-1 col-lg-1'> </div>
</div>
</div>
Please anyone can solve my issue will be greatfull. I need to dynamically Add and Remove Row with this two buttons.
Also if anyone have any reference on how to make master-detail form in php with bootstrap will support me well. Thank you in Advance.
To get a concept please check the following URL. I want to add Parts Name to Total as a new row when I press + Add More. Please note that the Parts Name comes from MySQL through PHP code ...
jsfiddle.net/imranctgbd/34djbLLn
Hi would have been helpful if there was a screenshot so i can fully understand your question. But here's what i fink you want to do.
to the cell holding ur delete checkbox, add , this means u have to create a delete.php and link it properly.
<td> <a href='delete.php?id=$id' class='button small blue'>Delete</a> </td>
then here's what you do in your delete page
request id or whatever you want from your table and run a query. see example beneath
<?php
require_once('core.php');
$id = $_REQUEST['id'];
$sql = "delete from bookings where id = '$id'";
$result = mysqli_query($conn,$sql);
if ($result){
$count = mysqli_affected_rows($conn);
if($count > 0){
$redirect = header('location:index.php');
echo $redirect;
}
}
?>
same principle can be applied for addition or you could just use javascript for that dynamically...
Related
Good day,
I've ran into a bit of a problem with my website.
I have a form which pulls a full table from my DB. Beside each record I have an 'Edit' and 'Remove' button (see image 1).
image 1
If I click on the edit button beside record 'Delete me', a modal appears and populates the value of each editable field with the current data available, and I can then edit each value and update the database. This works fine.
The problem I have; when I select one of the records where the 'Name' field is duplicated with a different 'Filling/Size' (for example, if I select 'Filling/Size' 5) it always updates and pre-populates the modal with the data from the first record in the table that shares the same 'Name'. Image 2 shows me clicking the 'Edit' button for record 1-5.
image 2
I've tried creating a foreach loop inside my foreach loop but that just duplicated every record many many times. My code is below. Any input or suggestions would be greatly appreciated.
<div class="card mb-3">
<div class="card-header">
<i class="fa fa-table"></i>Items</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" name="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Filling/Size</th>
<th>Category</th>
<th>Description</th>
<th>Price</th>
<th>Edit/Remove</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Filling/Size</th>
<th>Category</th>
<th>Description</th>
<th>Price</th>
<th>Edit/Remove</th>
</tr>
</tfoot>
<tbody>
<?php foreach ($result as $i => $row) { ?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->filling; ?></td>
<td><?php echo $row->category; ?></td>
<td><?php echo $row->description; ?></td>
<td><?php echo $row->price; ?></td>
<td id="editRemoveButtonsCell">
<button id="editButton" type="button" class="btn btn-outline-success" data-toggle="modal" data-target="#editItemModal<?php echo $row->name;?>">Edit</button>
<button id="removeButton" type="button" class="btn btn-outline-danger" data-toggle="modal" data-target="#removeItemModal<?php echo $row->name;?>">Remove</button></td>
</tr>
<!-- Delete Modal -->
<div class="modal" id="removeItemModal<?php echo $row->name;?>">
<div class="modal-dialog">
<form>
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Delete Item <?php echo $row->name?></h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
Are you sure you want to delete item <?php echo $row->name?> <?php echo $row->filling;?>? <b>This cannot be undone!</b>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<input type="hidden" value="<?php echo $row->name;?>" name="deleteItemName" id="deleteItemName">
<input type="hidden" value="<?php echo $row->filling;?>" name="deleteItemFilling" id="deleteItemFilling">
<button type="button" class="btn btn-cancel" data-dismiss="modal">Close</button>
<input type="submit" name="deleteItem" id="deleteItem" value="Delete" class="btn btn-danger" />
</div>
</div>
</form>
</div>
</div>
<!-- Edit Modal -->
<div class="modal" id="editItemModal<?php echo $row->name;?>" name="editItemModal<?php echo $row->name;?>">
<div class="modal-dialog">
<form>
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Edit Item <?php echo $row->name;?></h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="form-group">
<label for="itemNameUpdate">Name</label>
<input type="text" class="form-control" id="itemNameUpdate" name="itemNameUpdate" placeholder="Enter Item Name" value="<?php echo $row->name;?>">
<input type="hidden" value="<?php echo $row->name;?>" name="itemNameOriginal" id="itemNameOriginal">
<input type="hidden" value="<?php echo $row->filling;?>" name="itemFillingOriginal" id="itemFillingOriginal">
</div>
<div class="form-group">
<label for="itemFillingUpdate">Filling/Size</label>
<input type="text" class="form-control" id="itemFillingUpdate" name="itemFillingUpdate" placeholder="Enter Filling/Size" value="<?php echo $row->filling;?>">
</div>
<div class="form-group">
<label for="itemCategoryUpdate">Category</label>
<select class="form-control" id="itemCategoryUpdate" name="itemCategoryUpdate">
<?php echo '<option>'.$row->category.'</option>';?>
<?php foreach($categories as $category) {echo '<option>'.$category->name.'</option>';}?>
</select>
</div>
<div class="form-group">
<label for="itemDescriptionUpdate">Description</label>
<textarea class="form-control" id="itemDescriptionUpdate" name="itemDescriptionUpdate" rows="3" placeholder="Item description (optional)"><?php echo $row->description;?></textarea>
</div>
<div class="form-group">
<label for="itemPriceUpdate">Price</label>
<input type="text" class="form-control" id="itemPriceUpdate" name="itemPriceUpdate" placeholder="Enter Price" value="<?php echo $row->price;?>">
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-cancel" data-dismiss="modal">Close</button>
<input type="submit" name="editItem" id="editItem" value="Edit" class="btn btn-success" />
</div>
</div>
</form>
</div>
</div>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="card-footer small text-muted">Use the navigation bar to the left to edit the menu.</div>
</div>
</div>
All your code references are to $row->name and I would judge it to be bad practise to reference anything in the code by name. You want to be idenitifying by a unique identifier (typically a number) on each case. So you don't get this sort of ambiguity.
Image 2 shows me clicking the 'Edit' button for record 1-5.
You can't event clearly identify your own rows in this question, without needing to pull in outside data that is only co-incidentally different.
What you want is a unique identifier for each row of your database table.
This is something that is an absolute basic standard and can be read in the MySQL Dev Tutorial Here.
This SO question may also be helpful to you.
So you can update your MySQL (assuming that's your database):
ALTER TABLE users ADD uid SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
ADD INDEX (uid);
(also please see here as to which int type is best for your situation)
Once you have a unique identifier for each row, you need to then use that identifier on your code so, for example :
<input type="hidden" value="<?php echo $row->uid;?>"
name="deleteItemUniqueId" id="deleteItemUniqueId">
And
<div class="modal" id="editItemModal<?php echo $row->uid;?>"
name="editItemModal<?php echo $row->uid;?>">
And similarly apply this to your codebase throughout.
This stops any repetition of HTML ids and stops the code logic having issues with any ambiguity on the part of the identifying data given.
I want to print the display table from the HTML page. For example, I search 'from what id' to 'to what id'. After clicking on the search button, it will display the tables that have the details. I want to print that table in PDF format. So, do I need to create the table again in the PDF?
<form class="form-horizontal" action="trypdf.php" method="POST">
<div class="form-group form-group-sm">
<label for="inputName" class="control-label col-xs-2" style="margin-left:10%; margin-top:4%; font-size:15px;">Em Part No From:</label>
<div class="col-xs-3">
<input type="text" id="srt" name="from" placeholder="From EmPartNo" required="" style="margin-left:-7%; margin-top:18%; text-align:center;"
value="<?php echo $empartno_pass1;?>"/>
</div>
<div class="col-xs-1">
<button type="button" name="from" data-toggle="modal" data-target="#search1" data-id="from" style="margin-left:-190%; margin-top:70%;">S</button>
</div>
<label for="inputName" class="control-label col-xs-1" style="margin-left:-15%; margin-top:4%; font-size:15px;">To:</label>
<div class="col-xs-3">
<input type="text" id="srt2" name="to" placeholder="To EmPartNo" style="margin-left:-36%; margin-top:18%; text-align:center;"
value="<?php echo $empartno_pass2;?>"/>
</div>
<div class="col-xs-1">
<button type="button" name="to" data-toggle="modal" data-target="#search1" data-id="to" style="margin-left:-302%; margin-top:70%;">S</button>
</div>
Back to Menu
<center><input type="submit" value="Search" class="btn btn-primary" style="margin-left:-2%; width:100px; height:30px; text-align:center;"></center><br>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>EmPartNo</th>
<th>Supplier No</th>
<th>Supplier Cost</th>
<th>Description</th>
<th>Foreign Currency</th>
<th>Item Cost</th>
<th>Admin Cost</th>
<th>Cost</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$counter = 1;
$total = 0;
if (isset($count) and ($count > 0)) {
while($row = mysqli_fetch_assoc($result)){
$emPartNo = $row['emPartNo'];
$supplierPartNo = $row['supplierPartNo'];
$supplierCostPrice =$row['supplierCostPrice'];
$description = $row['description'];
$foreignCurrency =$row['foreignCurrency'];
$itemCost = $row['itemCost'];
$adminCost =$row['adminCost'];
$cost = $row['cost'];
echo"<tr>
<td>{$row['emPartNo']}</td>
<td>{$row['supplierPartNo']}</td>
<td align='right'>".number_format($row['supplierCostPrice'],2)."</td>
<td>{$row['description']}</td>
<td>{$row['foreignCurrency']}</td>
<td align='right'>".number_format($row['itemCost'],2)."</td>
<td align='right'>".number_format($row['adminCost'],2)."</td>
<td align='right'>".number_format($row['cost'],2)."</td>
</tr>";
}
mysqli_free_result($result);
}
?>
</tr>
</tbody>
</table>
</form>
Here is the example of an image that I want to display in PDF.
I have a table where I get the data from database than i need to update all rows at once. Inside each cell I have added input fields. Now i want to be able to update all users at once when I enter the data but I dont know how.
Below is a picture of my view:
#extends('admin/master')
#section('content')
<section class="content">
{{Form::open()}}
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<div class="col-lg-4">
<h3 class="box-title">INPUT EXAM RESULTS FOR EACH STUDENT: </h3>
</div>
<div class="pull-right col-lg-8">
<div class="col-lg-2 col-lg-offset-5 pull-left">
<select class="btn bg-navy" name="city" >
<option>Select City</option>
<option>Prishtin</option>
<option>Prizren</option>
</select>
</div>
<div class="col-lg-5 pull-right">
<div class="input-group">
<input type="text" name="search_input" class="form-control" placeholder="Search here...">
<div class="input-group-btn">
<button type="submit" class="btn btn-info"><i class="fa fa-search"></i> Search</button>
</div>
</div>
</div>
</div>
</div>
<div class="box-body">
<?php if (isset($data)) { ?>
<table id="example2" class="table table-bordered table-hover">
<thead>
<tr>
<th>{{Lang::get('messages.stid')}} </th>
<th>{{Lang::get('messages.name')}}</th>
<th>Subject 1</th>
<th>Subject 2</th>
<th>Subject 3</th>
<th>Subject 4</th>
</tr>
</thead>
<tbody>#foreach ($data as $row)
<tr>
<td>{{$row->id}}</td>
<td>{{$row->fname}} {{$row->lname}}</td>
<td><input type="text" name="sub1" class="form-control" placeholder="Add marks here..."></td>
<td><input type="text" name="sub2" class="form-control" placeholder="Add marks here..."></td>
<td><input type="text" name="sub3" class="form-control" placeholder="Add marks here..."></td>
<td><input type="text" name="sub4" class="form-control" placeholder="Add marks here..."></td>
</tr>
#endforeach
</tbody>
</table>
<button type="submit" class="col-lg-2 pull-right btn btn-success"><i class="fa fa-save"></i> Save</button>
<?php } ?>
</div>
</div>
</div>
</div>
{{Form::close()}}
</section>
{{ HTML::script('/admin/assets/js/jquery-2.2.3.min.js') }}
{{ HTML::script('/admin/assets/js/bootstrap.min.js') }}
{{ HTML::script('/admin/assets/js/jquery.dataTables.min.js') }}
{{ HTML::script('/admin/assets/js/dataTables.bootstrap.min.js') }}
<script>
$(function () {
$("#example1").DataTable();
$('#example2').DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false
});
});
</script>
#stop
//Controller
public function search_input(){
$input = Input::get('search_input');
$city = Input::get('city');
$data = Apply::where('exam_venue', '=', "$input")
->where('city_applied', '=', "$city")->get();
if (isset($_POST['save'])) {
}
return View::make('admin/exam/edit',compact('data'));
}
Your input elements need to be arrays, keyed by $row->id (I assume this is the primary key of your students table) to identify which student that row represents. For example:
<td><input type="text" name="sub1[{{ $row->id}}]" class="form-control" placeholder="Add marks here..."></td>
Then when you submit the data, look up the student by the array key and update their information accordingly. Something to the effect of:
$key = // extract id from sub1 array
Student::find($request->input($key));
// do updates here
// repeat for each sub input...
I did ask the same questions before but I dont understand why it doesn't work now. When I click to open the modal (for edit function), the data is not populate, only role_id is populated in the modal. Is it something to do with jquery version or Codeigniter new update or something else ? The following are my codes. appreciate your kind advice.
view/rolelist.php
The javascript goes here
<script type="text/javascript">
$(document).ready(function(){
$('.edit-row').on('click',function(){
var me = $(this);
var editModal = $('#myModalEdit');
editModal.find('#role_id').val(me.attr('data-roleID'));
editModal.find('#role_name').val(me.attr('data-roleName'));
editModal.find('#manage_user').val(me.attr('data-manageUser'));
editModal.find('#manage_product').val(me.attr('data-manageProduct'));
editModal.find('#manage_project').val(me.attr('data-manageProject'));
editModal.find('#manage_timeline').val(me.attr('data-manageTimeline'));
editModal.find('#fn_trace').val(me.attr('data-fnTrace'));
editModal.find('#fn_mapper').val(me.attr('data-fnMapper'));
editModal.find('#fn_testscript').val(me.attr('data-fnTestScript'));
editModal.find('#fn_project').val(me.attr('data-fnProject'));
$('#myModalEdit').modal('show');
});
});
</script>
HTML Code
<!-- Modal -->
<div class="modal fade" id="myModalEdit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Edit System Role <label id="role_name"></label></h4>
</div>
<form role="form" id="roleForm" action="<?php echo base_url().'admin/updateRole'; ?>" method= "POST">
<div class="modal-body">
<div class="form-group">
<label>Role ID [Auto-generate by system]</label>
<input type="text" class="form-control" name="role_id" id="role_id" readonly>
</div>
<div class="form-group">
<label>Role Name *</label>
<input type="text" class="form-control" name="role_name" id="role_name">
</div>
<div class="form-group">
<table class="table table-bordered table-striped table-condensed">
<thead style="background-color:#33658A; color:#FFF;">
<tr>
<th colspan="4"><strong><center>ADMIN FUNCTIONS</center></strong></th>
<th colspan="4"><strong><center>QA FUNCTIONS</center></strong></th>
</tr>
<tr>
<th><strong><center>MANAGE USER</center></strong></th>
<th><strong><center>MANAGE PRODUCT</center></strong></th>
<th><strong><center>MANAGE PROJECT</center></strong></th>
<th><strong><center>MANAGE TIMELINE</center></strong></th>
<th><strong><center>TRACE</center></strong></th>
<th><strong><center>MAPPER</center></strong></th>
<th><strong><center>TEST SCRIPT</center></strong></th>
<th><strong><center>PROJECT</center></strong></th>
</tr>
</thead>
<tbody>
<div class="checkbox">
<tr>
<td><input type="checkbox" name="manage_user" id="manage_user" value="manage_user" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage_product" id="manage_product" value="manage_product" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage_project" id="manage_project" value="manage_project" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage_timeline" id="manage_timeline" value="manage_timeline" style="margin-left:20px"></td>
<td><input type="checkbox" name="fn_trace" id="fn_trace" value="fn_trace" style="margin-left:20px"></td>
<td><input type="checkbox" name="fn_mapper" id="fn_mapper" value="fn_mapper" style="margin-left:20px"></td>
<td><input type="checkbox" name="fn_testscript" id="fn_testscript" value="fn_testscript" style="margin-left:20px"></td>
<td><input type="checkbox" name="fn_project" id="fn_project" value="fn_project" style="margin-left:20px"></td>
</tr>
</div> <!-- end checkbox -->
</tbody>
</table>
</div>
</div> <!-- end modal-body -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" value="submit" class="btn btn-primary" >Update Info</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div> <!-- /.modalEdit -->
<div class="col-lg-12">
<div class="content-panel">
<section id="unseen">
<table class="table table-bordered table-striped table-condensed">
<thead style="background-color:#33658A; color:#FFF;">
<tr>
<th rowspan="2"><h4><strong>ROLE ID</strong></h4></th>
<th rowspan="2"><h4><strong>ROLE NAME</strong></h4></th>
<th colspan="4"><h4><strong><center>ADMIN FUNCTIONS</center></strong></h4></th>
<th colspan="4"><h4><strong><center>QA FUNCTIONS</center></strong></h4></th>
<th rowspan="2"><h4><center><strong>ACTION</strong></center></h4></th>
</tr>
<tr>
<th><h4><strong>MANAGE USER</strong></h4></th>
<th><h4><strong>MANAGE PRODUCT</strong></h4></th>
<th><h4><strong>MANAGE PROJECT</strong></h4></th>
<th><h4><strong>MANAGE TIMELINE</strong></h4></th>
<th><h4><strong>TRACE</strong></h4></th>
<th><h4><strong>MAPPER</strong></h4></th>
<th><h4><strong>TEST SCRIPT</strong></h4></th>
<th><h4><strong>PROJECT</strong></h4></th>
</tr>
</thead>
<tbody>
<?php
if(!empty($data_role)):
foreach($data_role as $row)
{
?>
<tr>
<td align="center"><?php echo $row->role_id; ?></td>
<td><?php echo $row->role_name; ?></td>
<?php
echo '<td>'.$row->adm_manage_user.'</td>';
echo '<td>'.$row->adm_manage_product.'</td>';
echo '<td>'.$row->adm_manage_project.'</td>';
echo '<td>'.$row->adm_manage_timeline.'</td>';
echo '<td>'.$row->fn_trace.'</td>';
echo '<td>'.$row->fn_mapper.'</td>';
echo '<td>'.$row->fn_test_script.'</td>';
echo '<td>'.$row->fn_project.'</td>';
echo '<td class="text-center">';
?>
<a href="<?php echo base_url().'admin/roleRemove/'.$row->role_id; ?>">
<button type="button" data-hover="tooltip" title="Delete Role <?php echo $row->role_name; ?>" class="btn btn-default">
<i class="fa fa-times"></i>
</button>
</a>
<a class="edit-row" href="javascript:"
data-roleID="<?php echo $row->role_id; ?>"
data-roleName="<?php echo $row->role_name; ?>"
data-manageUser="<?php echo $row->adm_manage_user; ?>"
data-manageProduct="<?php echo $row->adm_manage_product; ?>"
data-manageProject="<?php echo $row->adm_manage_project; ?>"
data-manageTimeline="<?php echo $row->adm_manage_timeline; ?>"
data-fnTrace="<?php echo $row->fn_trace; ?>"
data-fnMapper="<?php echo $row->fn_mapper; ?>"
data-fnTestScript="<?php echo $row->fn_test_script; ?>"
data-fnProject="<?php echo $row->fn_project; ?>"
>
<button type="button" data-hover="tooltip" title="Edit Role <?php echo $row->role_name; ?>" class="btn btn-default">
<i class="fa fa-pencil"></i>
</button>
</a>
<?php
echo '</td>';
echo '</tr>';
}
endif;
?>
</tbody>
</table>
</section>
</div><!-- /content-panel -->
</div><!-- /col-lg-12 -->
use same name for all checkboxes if its related to each other.
<td><input type="checkbox" name="manage[]" id="manage_user" value="manage_user" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="manage_product" value="manage_product" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="manage_project" value="manage_project" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="manage_timeline" value="manage_timeline" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="fn_trace" value="fn_trace" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="fn_mapper" value="fn_mapper" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="fn_testscript" value="fn_testscript" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="fn_project" value="fn_project" style="margin-left:20px"></td>
And access the checkbox values with the name $this->input->post('manage'); .
I am inserting multiple line values from a html table form in to sql but it's only inserting the last table form value in my database. I can't figure out where the problem is.
Can you help me out with this?
This is my PHP:
$result = mysql_query("SELECT * FROM ex_marks WHERE session='$session' and cl_name='$cl_name' and cl_section='$cl_section' and subject='$subj' and exam='$exam' and date='$date' and roll_no='$rollno' and obtainmarks='$marks'");
if (mysql_num_rows($result) == 0)
{
mysql_query("INSERT INTO ex_marks(mid, session, cl_name, cl_section, name, fname, status, date, exam, roll_no, subject, obtainmarks, maxmarks, passmarks)
VALUES('', '$session', '$cl_name', '$cl_section', '$name','$fname', '$attendance', '$date', '$exam', '$rollno', '$subj','$marks','$maxmarks','$passmarks')") or die(mysql_error());
echo "<script type='text/javascript'>alert('Submitted Successfully!')</script>";
}
else
{
echo "<script type='text/javascript'>alert('Already Exist!')</script>";
}
}
And this is the form where values are inserted:
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">ASSIGN MARKS</h1>
<div class="col-lg-6">
<div class="panel">
<form method="post">
<!--<div class="form-group">
<input type="text" size="15" name="date" id="name[]" class="tcal form-control" placeholder="EXAM DATE" required="required"/>
</div>-->
<div class="form-group">
<input class="form-control" type="text" size="17" name="maxmarks" placeholder="TOTAL MARKS" required="required"/>
</div>
<div class="form-group">
<input class="form-control" type="text" size="17" name="passmarks" placeholder="PASS MARKS" required="required"/>
</div>
<button name="btn_sub" type="submit" class="btn btn-info">SUBMIT</button>
</div>
</div>
<!-- /.col-lg-12 -->
</div>
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
Session :
<?php
$session=$_GET['session'];
echo $session;?>
Class :
<?php
$cl_name=$_GET['cl_name'];
echo $cl_name;?>
Section :
<?php
$cl_section=$_GET['cl_section'];
echo $cl_section;?>
Subject :
<?php
$subj = $_GET['subj'];
echo $subj;?>
Exam Date :
<?php
$date=$_GET['date'];
echo $date;?>
Exam :
<?php
$exam=$_GET['exam'];
echo $exam;?>
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>NO.</th>
<th class="text-center">NAME</th>
<th class="text-center">ROLL NO</th>
<th class="text-center">FATHER NAME</th>
<th class="text-center">SCORED MARKS</th>
<th class="text-center">ATTENDANCE</th>
</tr>
</thead>
<tbody>
<?php
$key="";
if(isset($_POST['searchtxt']))
$key=$_POST['searchtxt'];
if($key !="")
$sql_sel1=mysql_query("SElECT * FROM ex_attendance WHERE session like '%$key%' and cl_name like '%$key%' and cl_section like '%$key%'");
else
$sql_sel1=mysql_query("select * from ex_attendance where session='$session' and cl_name='$cl_name' and cl_section='$cl_section' and exam='$exam' and date='$date' and subject='$subj'");
$i=0;
while($row1=mysql_fetch_array($sql_sel1))
{
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<tr class="odd gradeX">
<td><?php echo $i;?></td>
<td align="center"><input size="17" type="text" name="name" value="<?php echo $row1['f_name']." ".$row1['m_name']." ".$row1['l_name'];?>" readonly="readonly"/></td>
<td align="center"><input size="13" type="text" name="rollno" value="<?php echo $row1['roll_no']?>" readonly="readonly"/></td>
<td align="center"><input size="17" type="text" name="fname" value="<?php echo $row1['fname']?>" readonly="readonly"/></td>
<td align="center"><input size="17" type="text" name="marks" required="required"/></td>
<td align="center"><input size="17" type="text" name="attendance" id="name[]" value="<?php echo $row1['status'];?>" readonly="readonly"/></td>
</tr>
<?php }?>
</form>
</tbody>
</table>
</div>
</div>
<!-- /.table-responsive -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
</div>