I have my edit.blade.php file as below mentioned
<table class="table">
<thead>
<tr>
<th>Vendor</th>
<th>Item</th>
<th>Qty</th>
<th>Rate</th>
<th>Total</th>
<th>Description</th>
<th>Job No</th>
</tr>
</thead>
<tbody>
#foreach ($po_items as $po_item)
<tr>
<td><input type="text" class="form-control" name="vendor_name[]" id="vendor_name" value="{{$po_item->cost_item->vendor_company->name}}" readonly></td>
<td><input type="text" class="form-control" name="item_name[]" id="item_name" value="{{$po_item->cost_item->item->name}}" readonly></td>
<td><input type="text" class="form-control" name="qty[]" id="qty" value="{{$po_item->qty}}"></td>
<td><input type="text" class="form-control" name="rate[]" id="rate" value="{{$po_item->rate}}"></td>
<td><input type="text" class="form-control" name="total[]" id="total" value="{{$po_item->qty * $po_item->rate}}"></td>
<td><input type="text" class="form-control" name="description[]" id="description" value="{{$po_item->description}}"></td>
<td><input type="text" class="form-control" name="job_id[]" id="job_id" value="{{$po_item->cost_item->job_id}}" readonly></td>
<td>
<form action="{{action('Employee\POItemController#destroy', $po_item->id)}}" method="post">
{{csrf_field()}}
{{method_field('DELETE')}}
<button class="btn btn-danger" type="submit">Delete</button>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
<form action="{{ route('employee.poitem.update', $vendor_company_id )}}" method="post">
{{csrf_field()}}
{{method_field('PATCH')}}
#foreach ($po_items as $po_item)
<input type="hidden" name="cost_item_id[]" value="?">
<input type="hidden" name="qty[]" value="?">
<input type="hidden" name="rate[]" value="?">
<input type="hidden" name="description[]" value="?">
#endforeach
<button type="submit" class="btn btn-primary">Update</button>
</form>
Since there are two forms in the same page, i find it hard to pass new form values to the update function. I read on using the same session to solve this issue, but it wasn't clear enough for me to proceed with it
Instead of Making delete form you can do it with anchor tag. I don't know it is correct way or not but it works fine.
Delete
Hope this helps :)
Your input id values are incorrect. In HTML, an id should be unique across all HTML tags. When you make a foreach :
#foreach ($po_items as $po_item)
<tr>
<td><input type="text" class="form-control" name="vendor_name[]" id="vendor_name" value="{{$po_item->cost_item->vendor_company->name}}" readonly></td>
</tr>
#endforeach
you're assigning all inputs vendor_name to same id="vendor_name, which is W3C incorrect. You could use instead
#foreach ($po_items as $po_item)
<tr>
<td><input type="text" class="form-control" name="vendor_name[]" id="vendor_name_{{$po_item->id}}" value="{{$po_item->cost_item->vendor_company->name}}" readonly></td>
</tr>
#endforeach
But that's not the real problem here, you need upon submitting the UPDATE Form to read each input data and pushes it in hidden inputs.
Do you use vanilla Javascript or JQuery? With JQuery you can achieve it easier, you must put some scripts on the page that contains the forms. The idea is to find each input value for like qty, push them into array and convert that array to JSON string and put that JSON string as value to hidden qty input. Try this codes :
<table class="table">
<thead>
<tr>
<th>Vendor</th>
<th>Item</th>
<th>Qty</th>
<th>Rate</th>
<th>Total</th>
<th>Description</th>
<th>Job No</th>
</tr>
</thead>
<tbody id="table_inputs">
#foreach ($po_items as $po_item)
<tr>
<td><input type="text" class="form-control" name="vendor_name[]" id="vendor_name_{{$po_item->id}}" value="{{$po_item->cost_item->vendor_company->name}}" readonly></td>
<td><input type="text" class="form-control" name="item_name[]" id="item_name_{{$po_item->id}}" value="{{$po_item->cost_item->item->name}}" readonly></td>
<td><input type="text" class="form-control" name="qty[]" id="qty_{{$po_item->id}}" value="{{$po_item->qty}}"></td>
<td><input type="text" class="form-control" name="rate[]" id="rate_{{$po_item->id}}" value="{{$po_item->rate}}"></td>
<td><input type="text" class="form-control" name="total[]" id="total_{{$po_item->id}}" value="{{$po_item->qty * $po_item->rate}}"></td>
<td><input type="text" class="form-control" name="description[]" id="description_{{$po_item->id}}" value="{{$po_item->description}}"></td>
<td><input type="text" class="form-control" name="job_id[]" id="job_id_{{$po_item->id}}" value="{{$po_item->cost_item->job_id}}" readonly></td>
<td>
<form action="{{action('Employee\POItemController#destroy', $po_item->id)}}" method="post">
{{csrf_field()}}
{{method_field('DELETE')}}
<button class="btn btn-danger" type="submit">Delete</button>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
<form id="form_update_poitem" action="{{ route('employee.poitem.update', $vendor_company_id )}}" method="post">
{{csrf_field()}}
{{method_field('PATCH')}}
#foreach ($po_items as $po_item)
<input type="hidden" name="cost_item_id[]" >
<input type="hidden" name="qty[]" >
<input type="hidden" name="rate[]" >
<input type="hidden" name="description[]" >
#endforeach
<button type="submit" class="btn btn-primary">Update</button>
</form>
<script>
$(document).ready(function() {
console.log('document is ready, proceed to form update codes');
// find button form
var button = $('#form_update_poitem button');
// add onclick event
button.on('click', function(e){
// find input array input values, turn them into array and pass that array to Hidden Input array
var itemArr = [];
$("#table_inputs input[type='item_name']").each(function(){
itemArr.push($(this).val());
});
console.log(itemArr);
$("#form_update_poitem input[type='cost_item_name']").val(JSON.stringify(itemArr));
var qtyArr = [];
$("#table_inputs input[type='qty']").each(function(){
qtyArr.push($(this).val());
});
console.log(qtyArr);
$("#form_update_poitem input[type='qty']").val(JSON.stringify(qtyArr));
var rateArr = [];
$("#table_inputs input[type='rate']").each(function(){
rateArr.push($(this).val());
});
console.log(rateArr);
$("#form_update_poitem input[type='rate']").val(JSON.stringify(rateArr));
var descriptionArr = [];
$("#table_inputs input[type='description']").each(function(){
descriptionArr.push($(this).val());
});
console.log(descriptionArr);
$("#form_update_poitem input[type='description']").val(JSON.stringify(descriptionArr));
});
});
</script>
The rows are getting added in upper table only even though table id is different
The functionality shpuld work as I have included different ID for different table
Please heklpme to identify the error
THE JS is below
$(document).ready(function () {
$('#myTable').on('click', 'input[type="button"]', function () {
$(this).closest('tr').remove();
});
$('p input[type="button"]').click(function () {
$('#myTable').append('<tr><td><input type="text" class="form-control" name="aname[]" value="" placeholder="Input Name" /> </td><td><input type="amount" class="form-control" name="aamount[]" value="" placeholder="Input Value" /></td><td><input type="number" class="form-control" name="apriority[]" value="" placeholder="Input Value" /></td><td><input type="button" class ="btn btn-danger" value="x Delete" /></td></tr>')
});
$('#myTable1').on('click', 'input[type="button"]', function () {
$(this).closest('tr').remove();
});
$('p input[type="button"]').click(function () {
$('#myTable1').append('<tr><td><input type="text" class="form-control" name="dname[]" value="" placeholder="Input Name" /> </td><td><input type="amount" class="form-control" name="damount[]" value="" placeholder="Input Value" /></td><td><input type="number" class="form-control" name="dpriority[]" value="" placeholder="Input Value" /></td><td><input type="button" class ="btn btn-danger" value="x Delete" /></td></tr>')
});
});
Below is HTML
<div class="form-group">
<label for="grade">Grade</label>
<select class="form-control required alphanum" name="grade" id="grade" required>
<option value="">Please select...</option>
<?php fetch_grade($conn);
?>
</select>
</div>
<div class="form-group">
<label for="name">Basic Salary</label>
<input type="text" name="basic" id="basic" class="form-control" />
</div>
<div class="form-group">
<label for="overtime">Overtime Rate(Per Hour)</label>
<input type="text" name="overtime" id="overtime" class="form-control" />
</div>
Allowances
<br>
<p> <input type="button" class="btn btn-primary" value="+ Add Allowance"></p>
<table id="myTable" class="table table-condensed table-hover table-bordered table-hover table-responsive table-striped">
<thead>
<tr>
<th>Allowance Name</th>
<th>Amount</th>
<th>Display Priority</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" class="form-control" name="aname[]" value="" placeholder="Input Name" /> </td>
<td><input type="amount" class="form-control" name="aamount[]" value="" placeholder="Input Value" /></td>
<td><input type="number" class="form-control" name="apriority[]" value="" placeholder="Input Value" /></td>
<td><input type="button" class ="btn btn-danger" value="x Delete" /></td>
</tr>
</tbody>
</table>
Deductions
<p> <input type="button" class="btn btn-primary" value="+ Add Deduction"></p>
<table id="myTable1" class="table table-condensed table-hover table-bordered table-hover table-responsive table-striped">
<thead>
<tr>
<th>Deduction Name</th>
<th>Amount</th>
<th>Display Priority</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" class="form-control" name="dname[]" value="" placeholder="Input Name" /> </td>
<td><input type="amount" class="form-control" name="damount[]" value="" placeholder="Input Value" /></td>
<td><input type="number" class="form-control" name="dpriority[]" value="" placeholder="Input Value" /></td>
<td><input type="button" class ="btn btn-danger" value="x Delete" /></td>
</tr>
</tbody>
</table>
I am not sure where I am going wrong? I have searched various forum but didnt come with accurate solutions and was wonderingif someone canthrow light on this and how can I optmisie it
This selector bind some function twice:
$('p input[type="button"]')
which means it will only run for one table.
Add some class to the <p> element
<p class="btnMyTable"> <input type="button"
<p class="btnMyTable1"> <input type="button"
And bind to it:
$('p.btnMyTable input[type="button"]')
$('p.btnMyTable1 input[type="button"]')
public function fetch_item($item)
{
$this->db->where("pgroup",$item);
$this->db->select('*');
$this->db->from('itemmaster');
$this->db-
>join('pgroup','pgroup.pgroupid
= itemmaster.catcode','left
outer');
$query_result = $this->db->get()-
>result();
//pass query result as html
$output = '<table class="table
table-
striped table-bordered table-
hover">
<thead>
<tr>
<th>Product Name</th>
<th>Rate</th>
<th>Qty</th>
<th>amount</th>
</tr>
</thead>
<tbody>';
if($query_result !='false'){
foreach ($query_result as $key
=>
$value) {
$output .='<tr>
<td>'.$value-
>product_name.'</td>
<td><input style="width:100px"
name="rate" type="text"
class="form-
control input-xs" value=""></td>
<td><input style="width:100px"
name="qty" type="text"
class="form-
control input-xs" value="">
</td>
<td><input style="width:100px"
name="amount" type="text"
class="form-
control input-xs" value="">
</td>
</tr>';
}
}
$output .="</tbody>
</table>";
echo $output;
}
this is model code for fetching data and
created in table format..
my problm is how i done the calculation
like qty * value and display in value text
box.in model code i have created table in that table how do this calcuations.......
how i do the calculation for table that has been created in model page.
Update you foreach loop code from below code
$i=0;
foreach ($query_result as $key => $value) {
$output .='<tr>
<td>'.$value->product_name.'</td>
<td><input style="width:100px" name="rate" type="text" class="form-control input-xs" value="" id="rate_'.$i.'" onchange="calculate('.$i.')"></td>
<td><input style="width:100px" name="qty" type="text" class="form-control input-xs" value="" id="qty_'.$i.'" onchange="calculate('.$i.')"> </td>
<td><input style="width:100px" name="amount" type="text" class="form-control input-xs" value="" id="amount_'.$i.'">
</td></tr>';
$i++;
}
add below code into your view page make sure jquery min lode before this script
<script type="text/javascript">
function calculate(id){
var rate=$("#rate_"+id).val();
var qty=$("#qty_"+id).val();
if(qty=="")
qty=0;
if(rate=="")
rate=0;
var total=rate*qty;
$("#amount_"+id).val(total);
}
</script>
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 5 years ago.
this is the output
<?php
include_once('connection.php');
$StdID = $_REQUEST['txtID'];
$StdImage = $_REQUEST['txtImage'];
$FullName = $_REQUEST['txtFullname'];
$Address = $_REQUEST['txtAdd'];
$Bday = $_REQUEST['txtBday'];
$Grade = $_REQUEST['txtGrade'];
$Height = $_REQUEST['txtHeight'];
$Weight = $_REQUEST['txtWeight'];
$BloodPressure = $_REQUEST['txtBlood'];
$Gname = $_REQUEST['txtGname'];
$Contact = $_REQUEST['txtContact'];
$BCG = $_REQUEST['chkBCG'];
$Cardiac = $_REQUEST['chkCardiac'];
$Asthma1 = $_REQUEST['chkAsthma1'];
$Alcohol = $_REQUEST['chkAlcohol'];
$OPV1 = $_REQUEST['chkOpv1'];
$Thyroid = $_REQUEST['chkThyroid'];
$Chicken = $_REQUEST['chkChicken'];
$Tobacco = $_REQUEST['chkYosi'];
$OPV2 = $_REQUEST['chkOPV2'];
$Diabetes = $_REQUEST['chkDiabetes'];
$Measles = $_REQUEST['chkMeasles1'];
$Opv3 = $_REQUEST['chkOpv3'];
$Hypertension = $_REQUEST['chkHypertension'];
$Mumps = $_REQUEST['chkMumps1'];
$Food1 = $_REQUEST['txtFood1'];
$DPT1 = $_REQUEST['chkDpt1'];
$Tuberculosis = $_REQUEST['chkTuber'];
$Ulcer = $_REQUEST['chkUlcer'];
$Food2 = $_REQUEST['txtFood2'];
$DPT2 = $_REQUEST['chkdpt2'];
$Asthma2 = $_REQUEST['chkAsthma2'];
$Dengue = $_REQUEST['chkdengue'];
$Food3 = $_REQUEST['txtfood3'];
$Dpt3 = $_REQUEST['chkDpt3'];
$Kidney = $_REQUEST['chkKidney'];
$Head = $_REQUEST['chkHead'];
$Measles2 = $_REQUEST['chkMeasles2'];
$Cancer = $_REQUEST['chkCancer'];
$Std = $_REQUEST['chkstd'];
$Scar = $_REQUEST['chkScar'];
$Hepa = $_REQUEST['chkHepa'];
$Hypertension2 = $_REQUEST['chkHypertension2'];
$Mole = $_REQUEST['chkMole'];
$Std2 = $_REQUEST['chkStd2'];
$Kidney2 = $_REQUEST['chkKidney2'];
$Tattoo = $_REQUEST['chkTattoo'];
$OthersImmu = $_REQUEST['txtothersimmu'];
$Birthmark = $_REQUEST['txtBirthmark'];
$OthersImmu2 = $_REQUEST['txtothersimmu2'];
$OthersIll = $_REQUEST['txtothersill'];
$OthersImmu3 = $_REQUEST['txtothersimmu3'];
$OthersIll2 = $_REQUEST['txtothersill2'];
$Mens = $_REQUEST['txtmens'];
$sql = "INSERT INTO tbl_medics VALUES ('$StdID', '$StdImage', '$FullName', '$Address', '$Bday', '$Grade', '$Height', '$Weight', '$BloodPressure', '$Gname','$Contact', '$BCG', '$Cardiac', '$Asthma1', '$Alcohol', '$OPV1', '$Thyroid', '$Chicken','$Tobacco', '$OPV2', '$Diabetes', 'Measles', '$Opv3', '$Hypertension', '$Mumps', '$Food1', '$DPT1', '$Tuberculosis', '$Ulcer', '$Food2', '$DPT2', '$Asthma2', '$Dengue', '$Food3', '$Dpt3', '$Kidney', '$Head', '$Measles2', '$Cancer', '$Std', '$Scar', '$Hepa', '$Hypertension2', '$Mole', '$Std2', '$Kidney2', '$Tattoo', '$OthersImmu', '$Birthmark', '$OthersImmu2', '$OthersIll', '$OthersImmu3', '$OthersIll2', '$Mens')";
if ($conn->query($sql) === TRUE) {
header("Location: MedicRecords.php?SuccessfullyAdded");
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
This is my Input
<form action="AddMedicRecords.php" method="POST" enctype="multipart/form-data" style="border:1px solid #ccc">
<?php $id = $_GET['id'];
$sql = "SELECT * FROM tblstdpro where StdID = '$id'";
$result = mysqli_query($conn,$sql);
$count = 0;
while($row = mysqli_fetch_array($result)){
?>
<div class="box-body">
<div class="form-group">
<label><b>Student Image Location</b></label>
<input type="text" class="form-control" value="<?php echo $row['StdImage'];?>" name="txtImage" type="readonly" readonly></br>
<label><b>LRN</b></label>
<input type="text" class="form-control" value="<?php echo $row['StdID'];?>" name="txtID" required></br>
<label><b>Full Name</b></label>
<input type="text" class="form-control" value="<?php echo $row['Lname'];?>, <?php echo $row['Fname'];?> <?php echo $row['Mname'];?>" name="txtfullname" required></br>
<label><b>Address</b></label></br>
<input type="text" class="form-control" value="<?php echo $row['Street']; ?> , <?php echo $row['Barangay']; ?> <?php echo $row['Munic']; ?>, <?php echo $row['Province']; ?>" name="txtadd" required></br>
<label><b>Birthday</b></label>
<input type="text" class="form-control" value="<?php echo $row['Bday'];?>" name="txtbday" required></br>
<label><b>Grade/ Course</b></label></br>
<input type="text" class="form-control" value="<?php echo $row['Track'];?> - <?php echo $row['YearLvl'];?>" name="txtgrade" required></br>
<label><b>Height</b></label>
<input type="" class="form-control" placeholder="Enter Height" name="txtheight" required></br>
<label><b>Weight</b></label>
<input type="" class="form-control" placeholder="Enter Weight" name="txtweight" required></br>
<label><b>Blood Pressure</b></label>
<input type="" class="form-control" placeholder="Enter BP" name="txtblood" required></br>
</br>
<label><b><h3>*Person to be Notified in Case of Emergency</h3></b></label>
</br>
<label><b>Name:</b></label>
<input type="text" class="form-control" value="<?php echo $row['Mother'];?>" name="txtGname" required></br>
<label><b>Contact No.</b></label>
<input type="text" class="form-control" class="form-control" value="<?php echo $row['Contact'];?>" name="txtContact"></br>
<label><h3>*Kindly Check the Box Provided on the Left Side</h3></label>
<table class="table table-hover">
<thead>
<tr>
<th>IMMUNIZATION</th>
<th>FAMILY HISTORY</th>
<th>PREVIOUS ILLNESS</th>
<th>PERSONAL HISTORY</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="chkBCG" value="BCG"> BCG</td>
<td><input type="checkbox" name="chkCardiac" value="Cardiac Disease"> Cardiac Disease</td>
<td><input type="checkbox" name="chkAsthma1" value="Asthma"> Asthma</td>
<td><input type="checkbox" name="" value="chkAlcohol"> Alcohol Use</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv1" value="OPV 1"> OPV 1</td>
<td><input type="checkbox" name="chkThyroid" value="Thyroid Disease"> Thyroid Disease</td>
<td><input type="checkbox" name="chkChicken" value="Chicken Pox"> Chicken Pox</td>
<td><input type="checkbox" name="chkYosi" value="Tobacco Use"> Tobacco Use</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv2" value="OPV 2"> OPV 2</td>
<td><input type="checkbox" name="chkDiabetes" value="Diabetes Mellitus"> Diabetes Mellitus</td>
<td><input type="checkbox" name="chkMeasles1" value="Measles"> Measles</td>
<td>Allergy to Food, Drugs,Etc..</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv3" value="OPV 3"> OPV 3</td>
<td><input type="checkbox" name="chkHypertension" value="Hypertension"> Hypertension</td>
<td><input type="checkbox" name="chkMumps" value="Mumps"> Mumps</td>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood1"> </td>
</tr>
<td><input type="checkbox" name="ChkDpt1" value="DPT1"> DPT 1</td>
<td><input type="checkbox" name="chkTuber" value="Tuberculosis"> Tuberculosis</td>
<td><input type="checkbox" name="chkUlcer" value="Peptic Ulcer"> Peptic Ulcer</td>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood2"> </td>
</tr>
<td><input type="checkbox" name="chkDpt2" value="DPT 2"> DPT 2</td>
<td><input type="checkbox" name="chkAstma2" value="Asthma"> Asthma</td>
<td><input type="checkbox" name="chkDengue" value="Dengue"> Dengue</td>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood3"> </td>
</tr>
<tr>
<td><input type="checkbox" name="chkDpt3" value="DPT 3"> DPT 3</td>
<td><input type="checkbox" name="chkKidney" value="Kidney Disease"> Kidney Disease</td>
<td><input type="checkbox" name="chkHead" value="Head Injury"> Head Injury</td>
<td>Any Identification Mark:</td>
</tr>
<tr>
<td><input type="checkbox" name="chkMeasles2" value="Measles"> Measles</td>
<td><input type="checkbox" name="chkCancer" value="Cancer"> Cancer</td>
<td><input type="checkbox" name="chkStd" value="STD"> STD</td>
<td><input type="checkbox" name="chkScar" value="Scar"> 1. Scar</td>
</tr>
<tr>
<td><input type="checkbox" name="chkHepa" value="HEPA-B"> HEPA-B</td>
<td><input type="checkbox" name="chkSkin" value="Skin Disease"> Skin Disease</td>
<td><input type="checkbox" name="chkHypertension2" value="Hypertension"> Hypertension</td>
<td><input type="checkbox" name="chkMole" value="Mole"> 2. Mole</td>
</tr>
<tr>
<td>Others:</td>
<td><input type="checkbox" name="chkStd2" value="STD"> STD</td>
<td><input type="checkbox" name="chkKidney2" value="Kidney Problem"> Kidney Problem</td>
<td><input type="checkbox" name="chkTattoo" value="Tattoo"> 3. Tattoo</td>
</tr>
<tr>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersImmu"> </td>
<td></td>
<td>Others:</td>
<td><input type="checkbox" name="txtBirthmark" value="Birthmark"> 4. Birthmark</td>
</tr>
<tr>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersImmu2"> </td>
<td></td>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersIll"> </td>
<td></td>
</tr>
<tr>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersImmu3"> </td>
<td></td>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersIll2"> </td>
<td></td>
</tr>
</tbody>
</table>
<label><b>FOR FEMALE ONLY: Date of Last Menstrual Period:</b></label>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="date" placeholder="Enter Birthday" class="form-control" data-inputmask="'alias': 'mm/dd/yyyy'" data-mask name="txtMens" >
</div>
<!-- /.input group -->
</div>
<!-- /.form group -->
<div class="clearfix">
<button type="submit" name="submit" class="btn btn-block btn-primary btn-lg">Add Student</button>
<button type="button" class="btn btn-block btn-danger btn-lg">Cancel</button>
</form></br></br>
</div>
</form>
<?php
}
?>
Errors Says this
Notice: Undefined index: txtFullname in C:\wamp64\www\TestingThesis\AddMedicRecords.php on line 9
Error: INSERT INTO tbl_medics VALUES ('014-321', 'StdImage/014-321.jpg', '', '', '', '', '', '', '', 'Mommy','097576346', 'BCG', '', '', '', '', '', '','', '', '', 'Measles', '', '', '', '', '', '', '', '', '', '', '', '', '', 'Kidney Disease', '', '', '', '', '', '', '', 'Mole', '', '', '', '', '', '', '', '', '', '')
Data truncated for column 'StdID' at row 1
How can this be done when there are so many uncheck it errors bet when i check it all it goes in, how can i put a default value if it is uncheck?
The major issue is, when you are dealing with a checkbox, then you have to check whether it is checked or not like:
$value = ''; // Default value
if( isset($_REQUEST['checkbox_name']) )
{
$value = $_REQUEST['checkbox_name'];
}
apart form that, your code is open to SQL Injections. And you are inserting data into table without providing column names. Any changes to the table will break the whole thing.
Input name is wrong, change it to txtFullname instead of txtfullname.
<label><b>Full Name</b></label> <input type="text" class="form-control" value="<?php echo $row['Lname'];?>, <?php echo $row['Fname'];?> <?php echo $row['Mname'];?>" name="txtFullname" required>
Also i fixed all you invalid html tags:
<?php
$id = $_GET['id'];
$sql = "SELECT * FROM tblstdpro where StdID = '$id'";
$result = mysqli_query($conn,$sql); $count = 0;
while($row = mysqli_fetch_array($result)){ ?>
<form action="AddMedicRecords.php" method="POST" enctype="multipart/form-data" style="border:1px solid #ccc">
<div class="box-body">
<div class="form-group"> <label><b>Student Image Location</b></label> <input type="text" class="form-control" value="<?php echo $row['StdImage'];?>" name="txtImage" readonly><br>
<label><b>LRN</b></label> <input type="text" class="form-control" value="<?php echo $row['StdID'];?>" name="txtID" required><br>
<label><b>Full Name</b></label> <input type="text" class="form-control" value="<?php echo $row['Lname'];?>, <?php echo $row['Fname'];?> <?php echo $row['Mname'];?>" name="txtFullname" required><br>
<label><b>Address</b></label><br> <input type="text" class="form-control" value="<?php echo $row['Street']; ?> , <?php echo $row['Barangay']; ?> <?php echo $row['Munic']; ?>, <?php echo $row['Province']; ?>" name="txtadd" required><br>
<label><b>Birthday</b></label> <input type="text" class="form-control" value="<?php echo $row['Bday'];?>" name="txtbday" required><br>
<label><b>Grade/ Course</b></label><br> <input type="text" class="form-control" value="<?php echo $row['Track'];?> - <?php echo $row['YearLvl'];?>" name="txtgrade" required><br>
<label><b>Height</b></label> <input type="" class="form-control" placeholder="Enter Height" name="txtheight" required><br>
<label><b>Weight</b></label> <input type="" class="form-control" placeholder="Enter Weight" name="txtweight" required><br>
<label><b>Blood Pressure</b></label> <input type="" class="form-control" placeholder="Enter BP" name="txtblood" required><br> <br>
<label><h3>*Person to be Notified in Case of Emergency</h3></label> <br>
<label><b>Name:</b></label> <input type="text" class="form-control" value="<?php echo $row['Mother'];?>" name="txtGname" required><br>
<label><b>Contact No.</b></label> <input type="text" class="form-control" value="<?php echo $row['Contact'];?>" name="txtContact"><br>
<label><h3>*Kindly Check the Box Provided on the Left Side</h3></label>
<table class="table table-hover">
<thead>
<tr>
<th>IMMUNIZATION</th>
<th>FAMILY HISTORY</th>
<th>PREVIOUS ILLNESS</th>
<th>PERSONAL HISTORY</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="chkBCG" value="BCG"> BCG</td>
<td><input type="checkbox" name="chkCardiac" value="Cardiac Disease"> Cardiac Disease</td>
<td><input type="checkbox" name="chkAsthma1" value="Asthma"> Asthma</td>
<td><input type="checkbox" name="" value="chkAlcohol"> Alcohol Use</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv1" value="OPV 1"> OPV 1</td>
<td><input type="checkbox" name="chkThyroid" value="Thyroid Disease"> Thyroid Disease</td>
<td><input type="checkbox" name="chkChicken" value="Chicken Pox"> Chicken Pox</td>
<td><input type="checkbox" name="chkYosi" value="Tobacco Use"> Tobacco Use</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv2" value="OPV 2"> OPV 2</td>
<td><input type="checkbox" name="chkDiabetes" value="Diabetes Mellitus"> Diabetes Mellitus</td>
<td><input type="checkbox" name="chkMeasles1" value="Measles"> Measles</td>
<td>Allergy to Food, Drugs,Etc..</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv3" value="OPV 3"> OPV 3</td>
<td><input type="checkbox" name="chkHypertension" value="Hypertension"> Hypertension</td>
<td><input type="checkbox" name="chkMumps" value="Mumps"> Mumps</td>
<td><input type="text" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood1"> </td>
</tr>
<td><input type="checkbox" name="ChkDpt1" value="DPT1"> DPT 1</td>
<td><input type="checkbox" name="chkTuber" value="Tuberculosis"> Tuberculosis</td>
<td><input type="checkbox" name="chkUlcer" value="Peptic Ulcer"> Peptic Ulcer</td>
<td><input type="text" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood2"> </td>
</tr>
<td><input type="checkbox" name="chkDpt2" value="DPT 2"> DPT 2</td>
<td><input type="checkbox" name="chkAstma2" value="Asthma"> Asthma</td>
<td><input type="checkbox" name="chkDengue" value="Dengue"> Dengue</td>
<td><input type="text" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood3"> </td>
</tr>
<tr>
<td><input type="checkbox" name="chkDpt3" value="DPT 3"> DPT 3</td>
<td><input type="checkbox" name="chkKidney" value="Kidney Disease"> Kidney Disease</td>
<td><input type="checkbox" name="chkHead" value="Head Injury"> Head Injury</td>
<td>Any Identification Mark:</td>
</tr>
<tr>
<td><input type="checkbox" name="chkMeasles2" value="Measles"> Measles</td>
<td><input type="checkbox" name="chkCancer" value="Cancer"> Cancer</td>
<td><input type="checkbox" name="chkStd" value="STD"> STD</td>
<td><input type="checkbox" name="chkScar" value="Scar"> 1. Scar</td>
</tr>
<tr>
<td><input type="checkbox" name="chkHepa" value="HEPA-B"> HEPA-B</td>
<td><input type="checkbox" name="chkSkin" value="Skin Disease"> Skin Disease</td>
<td><input type="checkbox" name="chkHypertension2" value="Hypertension"> Hypertension</td>
<td><input type="checkbox" name="chkMole" value="Mole"> 2. Mole</td>
</tr>
<tr>
<td>Others:</td>
<td><input type="checkbox" name="chkStd2" value="STD"> STD</td>
<td><input type="checkbox" name="chkKidney2" value="Kidney Problem"> Kidney Problem</td>
<td><input type="checkbox" name="chkTattoo" value="Tattoo"> 3. Tattoo</td>
</tr>
<tr>
<td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersImmu"> </td>
<td></td>
<td>Others:</td>
<td><input type="checkbox" name="txtBirthmark" value="Birthmark"> 4. Birthmark</td>
</tr>
<tr>
<td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersImmu2"> </td>
<td></td>
<td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersIll"> </td>
<td></td>
</tr>
<tr>
<td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersImmu3"> </td>
<td></td>
<td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersIll2"> </td>
<td></td>
</tr>
</tbody>
</table> <label><b>FOR FEMALE ONLY: Date of Last Menstrual Period:</b></label>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"> <i class="fa fa-calendar"></i> </div> <input type="date" placeholder="Enter Birthday" class="form-control" data-inputmask="'alias': 'mm/dd/yyyy'" data-mask name="txtMens"> </div>
<!-- /.input group -->
</div>
<!-- /.form group -->
<div class="clearfix"> <button type="submit" name="submit" class="btn btn-block btn-primary btn-lg">Add Student</button> <button type="button" class="btn btn-block btn-danger btn-lg">Cancel</button> <br><br> </div>
</div>
</div>
</form>
<?php }?>
I want to filter the table by using multiple select checkbox by selecting multiple Company Name and the table will display the record related to the selected checkbox. It only able to select one checkbox and display one related record only but it cannot multiple select checkbox.
<form name="frmSearch" id="frmSearch" method="post" action="">
<label>Company Name </label>
<select id="multiple-checkboxes" multiple="multiple" name="COMPANYNAME">
<?php
$query = mysqli_query($conn_connection, "SELECT * FROM sl_iv GROUP by COMPANYNAME");
while ($row = mysqli_fetch_assoc($query)) {
echo "<option value='".$row["COMPANYNAME"]."'".($row["COMPANYNAME"]==$_POST["COMPANYNAME"] ? " selected" : "").">".$row["COMPANYNAME"]."</option>";
}
?>
</select>
<br></br>
<button type="submit" id="submit" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-search"></span> Search</button>
<a href="cust_due_list.php">
<button type="button" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-refresh"></span> RESET</button>
</a>
<br></br>
<table id="table">
<center>
<thead>
<tr class="item-row">
<th width="15%" style="text-align:center"><span>Doc No.</span></th>
<th width="10%" style="text-align:center"><span>Due</span></th>
<th width="5%" style="text-align:center"><span>Age</span></th>
<th width="20%" style="text-align:center"><span>Customer Name</span></th>
<th width="10%" style="text-align:center"><span>Ammount</span></th>
<th width="10%" style="text-align:center"><span>Payment</span></th>
<th width="10%" style="text-align:center"><span>OutStanding</span></th>
</tr>
</thead>
</center>
<tbody>
<?php
if(isset ($_POST['COMPANYNAME']))
{
$COMPANYNAME = $_POST['COMPANYNAME'];
$fetch = "SELECT sl_iv.DOCDATE, ar_iv.DUEDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME, ar_iv.DOCAMT, ar_iv.PAYMENTAMT FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.COMPANYNAME = '".$COMPANYNAME."' or sl_iv.DOCDATE <= '".$from."'";
$result = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");
}
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$docamt = $row['DOCAMT'];
?>
<tr class="item-row">
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DocNo" id=DocNo0 " name="DocNo " value="<?php echo htmlspecialchars($row[ 'DOCNO']);?>" readonly></td>
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DueDate" id="DueDate0" name="DueDate" value="<?php echo htmlspecialchars($row['DUEDATE']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DateAge" id="DateAge0" name="DateAge" value="<?php echo $dateage;?>" readonly>
</td>
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm CompanyName" id="CompanyName0" name="CompanyName" value="<?php echo htmlspecialchars($row['COMPANYNAME']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:right; font-size:15px" class="form-control input-sm TotalAmt" id="TotalAmt0" name="TotalAmt" value="<?php echo htmlspecialchars($row['DOCAMT']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:right; font-size:15px" class="form-control input-sm payment" id="payment0" name="payment" value="<?php echo htmlspecialchars($row['PAYMENTAMT']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:right; font-size:15px" class="form-control input-sm Total_Outstanding" id="Total_Outstanding0" name="Total_Outstanding" value="<?php echo number_format((float)$outstanding, 2, '.', '');?>" readonly>
</td>
</tr>
<?php
}
} else {
echo "0 results";
}
?>
</tbody>
</table>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#multiple-checkboxes').multiselect();
});
</script>
When you receive multiple-select POST it cames as array, so you should use "IN" operator in your mysql request instead of comparison.
Try to change one part of your code:
if(isset ($_POST['COMPANYNAME'])) {
$COMPANYNAME = $_POST['COMPANYNAME'];
$COMPANYNAME = is_array($COMPANYNAME) ? $COMPANYNAME : [$COMPANYNAME];
$companiesParam = '\''. join("', '", $COMPANYNAME) . '\'';
$fetch = "SELECT sl_iv.DOCDATE, ar_iv.DUEDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME, ar_iv.DOCAMT, ar_iv.PAYMENTAMT FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.COMPANYNAME IN (".$companiesParam.") or sl_iv.DOCDATE <= '".$from."'";
$result = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");
}