matchmaking function when button is submitted - mysql

I am making a matchmaking system. I have a button submit that already inserts entries of players to my matching table, but the thing is whenever I'm inserting it, it goes like this (Please see pic 1), My target is to make a matching where players who have the same level gets to match.
For example Handler1 = level 1 and Handler3 = level 1, they'll be matched because they have the same level.
How can I make this work? Thank you in advance.
Views:
<form autocomplete="off" action="<?php echo base_url('controller/create'); ?>" enctype="multipart/form-data" method="post">
<div class="card-body table-responsive py-3 px-3">
<table id="table_list" class="table table-bordered" cellspacing="0" style="width: 100%;">
<thead>
<tr>
<th>HandlerID </th>
<th>Handler </th>
<th>Level </th>
</tr>
</thead>
<tbody>
<?php foreach ($j->result() as $row) { ?>
<tr>
<td><input type="text" name="handlerID[]" value="<?php echo $row->handlerID; ?>"> </td>
<td><input type="text" name="handler[]" value="<?php echo $row->handler; ?>"> </td>
<td><input type="text" name="level[]" value="<?php echo $row->level; ?>"> </td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</form>
</div>
Controller:
public function create()
{
$handlerID = $this->input->post('handlerID');
$handler = $this->input->post('handler');
$level = $this->input->post('level');
$data = [];
for($i=0;$i<count($handlerID);$i++) { $data[$i]=array ('handlerID'=> $handlerID[$i], 'handler' => $handler[$i], 'level' => $level[$i]);
}
$this->model->createSomething($data);
Model:
public function createSomething($data)
{
$q = $this->db->insert_batch('matching',$data);
if ($q)
{
return TRUE;
}
else return FALSE;
}

Related

How to avoid redirecting to another page after submit button

I have created a simple form type page as follows,
<form action="" method="GET" >
<div class="input-group mb-3">
<input type="text" name="search" required value="<?php if(isset($_GET['search'])){echo $_GET['search']; } ?>" class="form-control" placeholder="Search data">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</form>
I need to type a text in search box(name ="search") and after clicking submit I need to filter the sql data as follows.
<?php
$con = mysqli_connect("10.62.96.133", "root", "", "cdrextend");
if(isset($_GET['search']))
{
$filtervalues = $_GET['search'];
$query="***";
$query_run = mysqli_query($con, $query);
if(mysqli_num_rows($query_run) > 0)
{
foreach($query_run as $items)
{
?>
<tr>
<td><?= $items['***']; ?></td>
<td><?= $items['***']; ?></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="2">No Record Found</td>
</tr>
<?php
}
}
?>
Whenever I hit submit button after typing something in text box, it redirects to login page and I am not getting any results.Can someone show me where I have messed up?
Hi change your forms submit action="" to action="<?php echo htmlspecialchars($_SERVER[" PHP_SELF "]);?>"
<form action="<?php echo htmlspecialchars($_SERVER[" PHP_SELF "]);?>" method="GET" >
<div class="input-group mb-3">
<input type="text" name="search" required value="<?php if(isset($_GET['search'])){echo $_GET['search']; } ?>" class="form-control" placeholder="Search data">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</form>

Custom filter and export filtered data into excel sheet not working in codeigniter

I have data table with search filed. I am trying to filter table using data range and order status. I want to filter table also using range and status and also want to export into excel sheet. Code is working for only search and simple export (Not filtered data).
Thanks
This is my file (View, Controller and Model)
View:-
<a class="pull-right btn btn-primary btn-xs" href="<?php echo base_url()?>order/createXLS"><i class="fa fa-file-excel-o"></i> Export Data</a>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title" >Custom Filter : </h3>
</div>
<div class="panel-body">
<form id="form-filter" method="POST" action="order/ajax_list" class="form-horizontal">
<div class="form-group">
<label for="FirstName" class="col-sm-2 control-label">From</label>
<div class="col-sm-4">
<input type="date" class="form-control" id="from">
</div>
</div>
<div class="form-group">
<label for="LastName" class="col-sm-2 control-label">To</label>
<div class="col-sm-4">
<input type="date" class="form-control" id="to">
</div>
</div>
<div class="form-group">
<label for="LastName" class="col-sm-2 control-label">Status</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="status">
</div>
</div>
<div class="form-group">
<label for="LastName" class="col-sm-2 control-label"></label>
<div class="col-sm-4">
<button type="button" id="btn-filter" class="btn btn-primary">Filter</button>
<button type="button" id="btn-reset" class="btn btn-default">Reset</button>
</div>
</div>
</form>
</div>
</div>
<table class="table table-bordered table-striped" id="mytable">
<thead>
<tr>
<th width="80px">No</th>
<th>Order Number</th>
<th>Service Date</th>
<th>Service Location</th>
<th>Customer Name</th>
<th>Contact Number</th>
<th>Order Status</th>
<th>Payment Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$start = 0;
foreach ($job_positions_data as $job_positions)
{
?>
<tr>
<td>
<?php echo ++$start ?>
</td>
<td>
<?php echo $job_positions->order_number ?>
</td>
<td>
<?php echo $job_positions->service_date ?>
</td>
<td>
<?php if($job_positions->service_location == 1)
{
echo 'vkool_branch';
}
else
{
echo 'customer_location' ;
}
?>
</td>
<td>
<?php echo $job_positions->firstname ?>
</td>
<td>
<?php echo $job_positions->contact_number ?>
</td>
<td>
<?php if($job_positions->order_status == 0)
{
echo 'Action Pending';
}
elseif($job_positions->order_status == 1)
{
echo 'Under Process' ;
}
elseif($job_positions->order_status == 2)
{
echo 'Cancelled' ;
}
elseif($job_positions->order_status == 3)
{
echo 'Completed' ;
}
elseif($job_positions->order_status == 4)
{
echo 'Refund' ;
}
?>
</td>
<td>
<?php if( $job_positions->payment_status == 1)
{
echo 'Pending (Pay at Store)';
}
elseif($job_positions->payment_status == 0)
{
echo 'Pending (Pay Online)';
}
elseif($job_positions->payment_status == 14)
{
echo 'Paid';
}?>
</td>
<td style="text-align:center" width="200px">
<i class="fa fa-search-plus"></i>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
$("#mytable").dataTable();
});
</script>
Controller : -
public function createXLS() {
$fileName = 'data-'.time().'.xlsx';
require_once APPPATH . "/third_party/PHPExcel/Classes/PHPExcel.php";
$orderInfo = $this->Order_model->get_For_Export();
$ordervalue = json_encode($orderInfo, true);
/*echo '<pre>';
print_r($orderInfo);
echo '</pre>';
exit;*/
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
// set Header
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'S.No');
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Order Number');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Service Location');
$objPHPExcel->getActiveSheet()->SetCellValue('D1', 'First Name');
$objPHPExcel->getActiveSheet()->SetCellValue('E1', 'Last Name');
$objPHPExcel->getActiveSheet()->SetCellValue('F1', 'Contact_No');
$objPHPExcel->getActiveSheet()->SetCellValue('G1', 'Order Status');
$objPHPExcel->getActiveSheet()->SetCellValue('H1', 'Payment Status');
// Style
$style = array(
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
),
'font' => array(
'bold' => true,
'color' => array('rgb' => '2F4F4F'),
'size' => 20,
),
);
$styleHeading = array(
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
),
'font' => array(
'bold' => true,
'size' => 15,
),
);
// set Row
$rowCount = 2;
foreach ($orderInfo as $element) {
$objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowCount, $element['id']);
$objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $element['order_number']);
$objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $element['service_location']);
$objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowCount, $element['firstname']);
$objPHPExcel->getActiveSheet()->SetCellValue('E' . $rowCount, $element['lastname']);
$objPHPExcel->getActiveSheet()->SetCellValue('F' . $rowCount, $element['contact_number']);
$objPHPExcel->getActiveSheet()->SetCellValue('G' . $rowCount, $element['order_status']);
$objPHPExcel->getActiveSheet()->SetCellValue('H' . $rowCount, $element['payment_status']);
$rowCount++;
}
// download file
$filename = "jobSummery". date("Y-m-d-H-i-s").".xls";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
public function list_view()
{
$job_positions = $this->Order_model->get_all();
$data = array(
'job_positions_data' => $job_positions
);
$this->load->view('order/index', $data);
}
Model :-
public function get_all()
{
$this->db->order_by('id', 'DESC');
$this->db->from('tbl_order');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function get_For_Export()
{
$this->db->order_by('id', 'DESC');
$this->db->from('tbl_order');
$query = $this->db->get();
$result = $query->result_array();
return $result;
}

MySQL Update Batch Process Remove Some Records

I have a program to store some financial values using batch process. Main tables are finance_budget & finance_budget_issue. finance_budget.budget_id = finance_budget_issue.budget_id (1 to many join)
I tried to edit some records using following code
Controller
public function editIssues($id)
{
$this->checkPermissions('edit', 'allocationIssues');
$bc = array(array('link' => 'budget/regIssues', 'page' => 'Allocation Issues'), array('link' => '#', 'page' => 'Edit'));
$meta = array('page_title' => 'Allocation Issues', 'bc' => $bc);
$this->form_validation->set_rules('vote_id', 'Vote', 'required');
$this->form_validation->set_rules('budget_date', 'Budget Date', 'required');
if ($this->form_validation->run() == true) {
$ustock = array(
'vote_id' => $this->input->post('vote_id'),
'budget_date' => $this->input->post('budget_date'),
'ref_no' => $this->input->post('ref_no'),
'usr' => $this->session->userdata('id_user'),
'added_time' => date('Y-m-d h:i:s'),
'budget_status' => 'issues',
'transfer_status' => 'Pending'
);
$count = count($this->input->post('office'));
$offices = $this->input->post('office');
$amount = $this->input->post('amount');
$notes = $this->input->post('notes');
for ($x = 0; $x < $count; $x++) {
$details[$x]['budget_id'] = $id;
$details[$x]['office'] = $offices[$x];
$details[$x]['amount'] = $amount[$x];
$details[$x]['notes'] = $notes[$x];
}
}
if ($this->form_validation->run() == true && $this->Budget_model->editIssuedAllocations($ustock, $details, $id)) {
$this->session->set_flashdata('message', 'Successfully Updated ..!!');
redirect('budget/regIssues');
} else {
$this->data['vote'] = $this->Budget_model->getVote(array('office_id'=>$this->session->userdata('office_id')));
$this->data['office'] = $this->Budget_model->getOffice();
$this->data['issues'] = $this->Budget_model->budgetById($id);
$this->render('budget/editIssues', $meta, $this->data);
}
}
Model
function editIssuedAllocations($ustock,$details,$id)
{
if(!empty($id)){
$this->db->trans_start();
$this->db->update('finance_budget',$ustock,array('budget_id'=>$id));
if($id!=1){
$this->db->where('budget_id', $id);
$this->db->delete('finance_budget_issue');
$this->db->insert_batch('finance_budget_issue', $details);
}
$this->db->trans_complete();
return $this->db->trans_status();
}
return false;
}
View
<?php
if (!empty($purchase)) {
$details = $purchase;
$purchase = $purchase[0];
}
?>
<script type="text/javascript">
$(document).ready(function () {
var i = $('#last').val();
$(".add-new").click(function () {
i++;
// $('.tab_logic').append();
$('#addr' + i).html("<td><a href='javascript:void(0);' id='add-post' class='external add-new'><i style='color: #00C853 !important;' class='fa fa-2x fa-plus-circle'></i></a></td>" +
"<td><select name='office[]' id='office" + i + "' class='select2 form-control' required>" +
"<option value=''></option>" +
<?php
if (!empty($office)) {
foreach ($office as $row) {
?>
"<option value='<?= $row->office_id ?>'><?= addslashes($row->office_name) ?></option>" +
<?php
}
}
?>
"</select></td>" +
"<td><input name='amount[]' type='number' step='any' placeholder='Amount' class='form-control input-md' required></td>" +
"<td><input name='notes[]' type='text' placeholder='Notes' class='form-control input-md'></td>" +
"<td><a href='javascript:void(0);' class='external remove'><i style='color: #dd4b39 !important;' class='fa fa-2x fa-minus-circle' id='addIcon'></i></a></td>");
$('#tab_logic').append('<tr id="addr' + (i + 1) + '"></tr>');
$('#i').val(i);
// alert($('#i').val());
$('#item' + i).select2();
});
$(document).on("click", ".remove", function () {
var count = $('#tab_logic>tbody').children().length;
if (count > 0) {
$(this).closest('tr').remove();
}
});
});
</script>
<div class="box box-info">
<div class="box box-info collapsed-box">
<div class="box-header with-border">
<h3 class="box-title">Edit Issued Allocations</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" style="font-size: 16px;" data-widget="collapse"><i
class="fa fa-plus"></i>
</button>
</div>
<!-- /.box-tools -->
</div>
<!-- /.box-header -->
<div class="box-body" style="display: block">
<form action="<?= site_url('budget/editPurchase/' . $purchase->budget_id) ?>" method="post">
<div class="row">
<div class="col-md-2">
<div class="form-group"><label>Budget ID</label>
<input type="text" name="budget_id" id="budget_id" class="form-control" disabled
value="<?= $purchase->budget_id ?> ">
</div>
</div>
<div class="col-md-4">
<div class="form-group"><label>වැය ශීර්ෂය</label>
<select name="vote_id" id="vote_id" class="form-control select2" required>
<option value="<?= $purchase->vote_id ?>"><?= $purchase->vote ?></option>
<?php
if (!empty($vote)) {
foreach ($vote as $row) {
?>
<option value="<?= $row->vote_id ?>"><?= $row->vote ?></option>
<?php
}
}
?>
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group"><label>යොමු / ගොණු අංකය</label>
<input type="text" name="ref_no" id="ref_no" class="form-control"
value="<?= $purchase->ref_no ?>">
</div>
</div>
<div class="col-md-2">
<div class="form-group"><label>දිනය</label>
<input type="date" name="budget_date" id="budget_date" class="form-control"
value="<?= $purchase->budget_date ?>">
</div>
</div>
</div>
<div class="col-md-12 column">
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr>
<th class="text-center">
</th>
<th class="text-center">
Office
</th>
<th class="text-center">
Amount
</th>
<th class="text-center">
Notes
</th>
<th class="text-center">
</th>
</tr>
</thead>
<tbody>
<?php
//dd($details);
$x = 0;
foreach ($details as $i => $values) {
// foreach ($values as $key => $value) {
$x = $i;
?>
<tr id='addr0'>
<td>
<a href="javascript:void(0);" id="add-post" class="external add-new"><i
style="color: #00C853 !important;"
class="fa fa-2x fa-plus-circle"></i></a>
</td>
<td style="width: 50%">
<input type="hidden" name="i" id="i" value="<?= $i ?>">
<select name="office[]" id="<?= "office" . $i ?>" class="form-control select2" required>
<option value="<?= $details[$i]->office_id ?>"><?= $details[$i]->office_name ?></option>
<?php
if (!empty($office)) {
foreach ($office as $row) {
?>
<option value="<?= $row->office_id ?>"><?= $row->office_name ?></option>
<?php
}
}
?>
</select>
</td>
<td>
<input type="number" name='amount[]' placeholder='Amount' class="form-control"
value="<?= (-1) * $details[$i]->amount ?>" required/>
</td>
<td>
<input type="text" name="notes[]" placeholder='Notes'
value="<?= $details[$i]->notes ?>" class="form-control"/>
<input type="hidden" name="table_id"
value="<?= $details[$i]->notes ?>">
</td>
<td><a href='javascript:void(0)' class='external remove'><i
style='color: #dd4b39 !important;'
class='fa fa-2x fa-minus-circle ' id='addIcon'></i></a>
</td>
</tr>
<tr id='addr1'></tr>
<?php
//print " $key => $value\n";
// }
//print "}\n";
}
?>
</tbody>
</table>
</div>
<!--table-->
<div class="row">
<div class="col-md-8"></div>
<div class="col-md-4">
<input type="hidden" value="<?= $x ?>" name="last" id="last">
<input type="submit" value="Update" class="btn btn-primary btn-block">
</div>
</div>
</form>
<!--end of table-->
</div>
</div>
</div>
Desired Output
Should be edit some values in the finance_budget & finance_budget_issue tables that related with same budget_id (Eg:- budget_id =2995)
Error
After editing some values in my view that is working & save properly. When I press the save button in my view without editing any value, the record in finance_budget_issue table that is related to finance_budget table by budget_id is deleted.
I can not understand what I am going wrong ? Can anyone help me ?
You could modify the model to check whether $details are empty or not to leave the finance_budget_issue table intact :
function editIssuedAllocations($ustock,$details,$id)
{
if(!empty($id)){
$this->db->trans_start();
$this->db->update('finance_budget',$ustock,array('budget_id'=>$id));
if($id!=1 && !empty($details[0])){
$this->db->where('budget_id', $id);
$this->db->delete('finance_budget_issue');
$this->db->insert_batch('finance_budget_issue', $details);
}
$this->db->trans_complete();
return $this->db->trans_status();
}
return false;
}
I have modified the for loop as follows in the controller.
$count = count($this->input->post('office'));
$offices = $this->input->post('office');
$votes = $this->input->post('vote_id');
$amount = $this->input->post('amount');
$notes = $this->input->post('notes');
$bdate = $this->input->post('budget_date');
for ($x = 0; $x < $count; $x++) {
$details[$x]['budget_id'] = $id;
$details[$x]['office'] = $offices[$x];
$details[$x]['vote_id'] = $votes[$x];
$details[$x]['amount'] = (-1)*$amount[$x];
$details[$x]['notes'] = $notes[$x];
$details[$x]['budget_date'] = $bdate[$x];
$details[$x]['status'] = 1;
}
Now the issue was fixed partially. But the saving vote_id of finance_budget_issue table is incorrect without editing.

display table values in view depending on id in codeigniter

I have one view candidate details form in my application.
In that I gave one button called scheduled interview.
So when I click on the button it redirect the page to candidate process page with the candidate_id and user_id in the url.
And in the candidate_process page I have one form with some details and under the form I display all the records from database in data table.
I want to display the records only for the particular candidate.I don't want to display all the records.
Here is my view:
<form method="post" action="" id="form">
<b>Date </b>:<input type="text" name="date" id="date"><br><br>
<input type="hidden" name="candidate_id" value="<?php echo $getCandidate['candidate_id']; ?>">
<input type="hidden" name="user_id" value="<?php echo $getCandidate['user_id']; ?>">
<div class="form-group">
<label><b>Select Interview Type:</b></label>
<select class="form-control" id="interview_type_id" name="interview_type_id" >
<option value="" disabled selected>Interview Type</option>
<?php foreach($interviewtype as $rows) { ?>
<option value="<?php echo $rows->interview_type_id?>"><?php echo ucfirst($rows->interview_type_name)?></option>
<?php } ?>
</select>
</div><br>
<div class="form-group">
<label><b>Select Status:</b></label>
<select class="form-control" id="status_type_id" name="status_type_id" >
<option value="" disabled selected>Status Type</option>
<?php foreach($statustype as $rows) { ?>
<option value="<?php echo $rows->status_type_id?>"><?php echo ucfirst($rows->status)?></option>
<?php } ?>
</select>
</div><br>
<button type="submit" name="submit" value="submit" class="btn btn-primary" value="submit">Submit</button>
<button type="submit" id="submit" name="submit" class="btn btn-primary" value="schedule" onclick="ScheduleNextRound();">Schedule Next Round</button><br></br>
</form>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h3>Reports</h3>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-body">
<table id="example1" class="table table-bordered table-hover">
<thead>
<tr>
<th>Interview Date</th>
<th>Candidate</th>
<th>interview</th>
<th>status</th>
<th>Vendor</th>
</tr>
</thead>
<?php foreach ($view_candidates as $idata){ ?>
<tbody>
<tr id="domain<?php echo $idata->candidate_seletion_id;?>">
<td><?php echo $idata->date;?></td>
<td><?php echo $idata->f_name;?></td>
<td><?php echo $idata->interview_type_name;?></td>
<td><?php echo $idata->status;?></td>
<td><?php echo $idata->first_name;?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
</div>
</section>
</div>
Controller:
function candidate_process($candidateid,$userid){
$data["msg"]="";
$this->load->model('CandidateModel');
$data['statustype']=$this->CandidateModel->getstatustypes();
$data['interviewtype']=$this->CandidateModel->getinterviewtypes();
$data['candidate']=$this->CandidateModel->getcandidates();
$data['usertype']=$this->CandidateModel->getvendors();
$data['getCandidate'] = $this->CandidateModel->get_candidate_detail($candidateid);
$data['view_candidates'] = $this->CandidateModel->getcandidateselection();//this is my table view
if($this->input->post('submit')=="submit"){
$this->CandidateModel->add_candidate_selection($this->input->post());
redirect(base_url('Candidate/view_candidate_selection'));
}
$this->load->view('Candidates/candidate_process',$data);
}
Model1:
public function add_candidate_selection($data){
$data=array(
'candidate_id'=>$this->input->post('candidate_id'),
'user_id'=>$this->input->post('user_id'),
'status_type_id'=>$this->input->post('status_type_id'),
'interview_type_id'=>$this->input->post('interview_type_id'),
'date'=>$this->input->post('date')
);
$this->db->insert('candidate_selection', $data);
//print_r($data);
}
MOdel2:
public function getcandidateselection(){
$this->db->select('*');
$this->db->from('candidate_selection');
$this->db- >join('candidates_details','candidates_details.candidate_id=candidate_selection.candidate_id');
$this->db->join('interview_types','interview_types.interview_type_id=candidate_selection.interview_type_id');
$this->db->join('status_types','status_types.status_type_id=candidate_selection.status_type_id');
$this->db->join('users','users.user_id=candidate_selection.user_id');
$query = $this->db->get();
//echo $this->db->last_query();
return $query->result();
}
Can anyone help me how to do this..
Thanks in advance.
Replace the Following code in your model function
function getcandidateselection($candidateid)
{
$this->db->join('candidate_selection as cs','cs.candidate_id = cd.candidate_id');
$this->db->join('status_types as st','st.status_type_id = cs.status_type_id');
$this->db->where('cd.candidate_id',$candidateid);
$q = $this->db->get('candidates_details as cd');
return $q->result();
}
Hope it will solve your problem

Radio button automatically checked when user checks radio button

How do I make a radio button automatically check when i press a radio button?
I have 2 tables, when i click a radio button in table1, the radio button in table2 should also be checked.
here is the radio button code for table1
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="COD") echo "checked";?> value="COD"></td>
<td><img src="img/Cash on Delivery.jpg" alt="COE" class="picture" height="90" width="125"/></td>
<td><p>This service is only available for Meto Manila and Metro Cebu.<p>
<div id='price'> Additional ₱180 </div></td>
</tr>
and here the radio button in table2 that needs to be automatically checked when i check the radio button in table1
<tr>
<td><input type="radio" name="carrier" <?php if (isset($payment) && $payment=="COD") echo "checked";?> value="COD"></td>
<td><img src="img/Cash on Delivery.jpg" height="90" width="125"/></td>
<td><p>Pay with your Cash on Delivery (COD)<br>Choose this option if you have selected COD under shipping. Otherwise, choose other options for payment.<p></td>
</tr>
Here are the full codes.
if(isset($_GET['command']) && $_GET['command']=='update'){
$first_name=$_SESSION['first_name'];
$email=$_SESSION['email'];
$home_address=$_SESSION['home_address'];
$mobile_phone=$_SESSION['mobile_phone'];
$carrier=$_REQUEST['carrier'];
$payment=$_REQUEST['payment'];
$result=mysql_query("insert into customers values('','$first_name','$email','$home_address','$mobile_phone','$carrier','$payment')");
$customerid=mysql_insert_id();
date_default_timezone_set("Asia/Hong_Kong");
$date=date('Y-m-d h:i:s');
$result=mysql_query("insert into orders values('','$date','$customerid')");
$orderid=mysql_insert_id();
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_prod_price($pid);
mysql_query("insert into order_detail values ($orderid,$pid,$q,$price)");
}
header('refresh: 0; url=homeframe.html'); // to be redirected
exit(); // para mawala ang puta, tumigil ang script.
}
// else if(isset($_REQUEST['success']) && $_REQUEST['success']=='1'){
// header('refresh: 0; url=samplebrand.php');
// $message = "Thank you for buying, You will now be redirected";
// echo("<script type='text/javascript'>alert('$message');</script>");
// }
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Billing Info</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script language="javascript">
function validate(){
var f=document.form1;
f.command.value='update';
f.submit();
alert("Order submitted");
}
$('#super').change(function(){
var radio1 = $('input:radio[name=carrier]:checked').val();
if(radio1 == 'on'){
$( "input:radio[name=carrier2]" ).prop( "checked", true ).checkboxradio( "refresh" );
}
});
</script>
<style>
#price{
color:red;
font-size:20px;
padding-right: 10px;
font-family: "Times New Roman", Times, serif;
float:right;
}
td{
display:block;
}
</style>
</head>
<body>
<form name="form1" onsubmit="return validate()">
<input type="hidden" name="command" />
<div align="center">
<h1 align="center">Shipping and Payment</h1>
<table border="0" cellpadding="2px">
<tr><td>Order Total:</td><td>₱ <?php echo get_order_total()?></td><td> </td>
</tr>
</table>
<center><h1>Shipping Method</h1></center>
<form method="post">
<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?> value="LBC"></td>
<td><img src="img/LBC.jpg" alt="LBC" class="picture"/></td>
<td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial.<p>
<div id='price'> Additional ₱250 </div></td>
</tr>
<tr>
<td><input type="radio" id="super" name="carrier" <?php if (isset($carrier) && $carrier=="COD") echo "checked";?> value="COD"></td>
<td><img src="img/Cash on Delivery.jpg" alt="COE" class="picture" height="90" width="125"/></td>
<td><p>This service is only available for Meto Manila and Metro Cebu.<p>
<div id='price'> Additional ₱180 </div></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="Personal") echo "checked";?> value="Personal"></td>
<td><img src="img/buybranded2.jpg" alt="buybranded" class="picture"/></td>
<td><p>The Shipping takes 2-3 days after processing for NCR and 3-5 days for any provincial.<p>
<div id='price'> Additional ₱100 </div></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="NextDayDelivery") echo "checked";?> value="NextDayDelivery"></td>
<td><img src="img/NextdayDelivery.jpg" alt="NextDayDelivery" class="picture"/></td>
<td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial.<p>
<div id='price'> Additional ₱150 </div></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="SameDayDelivery") echo "checked";?> value="SameDayDelivery"></td>
<td><img src="img/Same day Delivery.jpg" alt="SameDayDelivery" class="picture"/></td>
<td><p>Available only for NCR. Get your sporting good/s the same day you purchase the item. Cutoff is 12noon.<p>
<div id='price'> Additional ₱250 </div></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?> value="PickUp"></td>
<td><img src="img/Pick-up.jpg" alt="Pick-Up" class="picture"/></td>
<td><p>Office hours: 10:00 am to 6:00 pm<p>
<div id='price'> Free!! </div></td>
</tr>
</table>
<br>
<br>
<center><h1>Payment Method</h1></center>
<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='centerdown'>
<tr>
<td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="BPI") echo "checked";?> value="BPI"></td>
<td><img src="img/BPI.jpg"></td>
<td><p>Pay by BPI bank deposit (we need confirmation of payment through email.)<p></td>
</tr>
<!--
<tr>
<td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="PayPal") echo "checked";?> value="PayPal"></td>
<td><img src="img/paypal.gif"></td>
<td><p>Pay with your PayPal account, credit card (CB, Visa, Mastercard...), or private credit card.<p></td>
</tr>
-->
<tr>
<td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="PickUp") echo "checked";?> value="PickUp"></td>
<td><img src="img/cashondelivery.gif"></td>
<td><p>Pick up. You have 5 days reservation period. You pay for the merchandise upon pick-up<p></td>
</tr>
<tr>
<td><input type="radio" name="carrier2" <?php if (isset($payment) && $payment=="COD") echo "checked";?> value="COD"></td>
<td><img src="img/Cash on Delivery.jpg" height="90" width="125"/></td>
<td><p>Pay with your Cash on Delivery (COD)<br>Choose this option if you have selected COD under shipping. Otherwise, choose other options for payment.<p></td>
</tr>
</table>
<table>
<tr><td><!--<input type="submit" value="Place Order"/> --> <input type="button" value="Confirm Order" onclick="window.location='quotation.php?'"></td></tr>
</table>
</form>
</div>
</form>
</body>
</html>
You could achieve this using JQuery. Assuming your forms have ids of form1 and form2:
<script>
$(document).ready(function () {
$("#form1 input[name='carrier']").click(function () {
if (this.checked) {
$("#form2 input[name='carrier']").prop("checked", true);
} // end if checked
});
}); // end doc ready
</script>
You will also need to include a reference to the JQuery library, before adding the aforementioned code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Please note that this will only update the form2 carrier radio button when the form1 button is clicked, and not the other way around.
See this JSFiddle as an example.
i slightly change your second radio name, and you can automatically set it with jquery like below :
$('input:radio[name=carrier]').change(function(){
var radio1 = $('input:radio[name=carrier]:checked').val();
if(radio1 == 'on'){
$( "input:radio[name=carrier2]" ).prop( "checked", true ).checkboxradio( "refresh" );
}
});
DEMO