Twitter bootstrap always same content - php

I'm using twitter bootstrap modals for some update of contacts, but I have some problems. The modal always display the information of the first contact. However when I display the information outside the modal, this is displayed in the correct form
<?php foreach($contacts as $contact): ?>
<?php if($school==$contact->Schools_id): ?>
<table class="table table-bordered table-hover">
<tbody><br>
<button role="button" class="btn"><?php echo anchor('contacts/delete_contact/'.$contact->Contacts_id,' <i class="icon-remove"></i>'); ?></button>
<i class="icon-pencil"></i>
<tr>
<td>Name</td>
<td><?php echo $contact->name. " ". $contact->last_name; ?></td>
</tr>
<tr>
<td>Title</td>
<td><?php echo $contact->title; ?></td>
</tr>
<tr>
<td>Phone</td>
<td><?php echo $contact->phone; ?> </td>
</tr>
<tr>
<td>Email</td>
<td><?php echo $contact->email; ?></td>
</tr>
<div id="UpdateContact" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" tabindex="-1" aria-hidden="true">
<div class="modal-header">
<?php $hidden = array('contact_id' => $contact->Contacts_id,
'school_id' => $contact->Schools_id);
echo form_open_multipart('contacts/update_contact', "", $hidden); ?>
<h3>Update Contact</h3>
</div>
<div class="modal-body">
<label for="name">First Name <span class="required">*</span></label>
<input id="name" type="text" name="name" maxlength="20" ]
value="<?php echo set_value('name', $contact->name ); ?>" />
<br><br>
<label for="last_name">Last Name <span class="required">*</span></label>
<input id="last_name" type="text" name="last_name" maxlength="20" ]
value="<?php echo set_value('last_name', $contact != NULL ? $contact->last_name : " " ); ?>" />
<br><br>
<label for="title">Title <span class="required">*</span></label>
<input id="title" type="text" name="title" maxlength="45" ]
value="<?php echo set_value('title', $contact != NULL ? $contact->title : " " ); ?>" />
<br><br>
<label for="phone">Phone<span class="required">*</span></label>
<input id="phone" type="text" name="phone" maxlength="11" ]
value="<?php echo set_value('phone', $contact != NULL ? $contact->phone : " " ); ?>" />
<br><br>
<label for="email">Email<span class="required">*</span></label>
<input id="email" type="text" name="email" maxlength="45" ]
value="<?php echo set_value('email', $contact != NULL ? $contact->email : " " ); ?>" />
</div>
<div class="modal-footer">
<?php echo form_submit( array('class' => 'btn btn-primary', 'name' =>'submit', 'value' => 'Submit')); ?>
<?php echo form_close(); ?>
</div>
</div>
</div>
</tbody>
</table>
<?php endif ?>
<?php endforeach ?>
Some of the solutions I found in this question Twitter bootstrap remote modal shows same content everytime was:
<script type="text/javascript">
$(document).ready( function(){
$('#UpdateContact').on('hide', '.modal', function () {
$(this).removeData('modal');
});
});
</script>
But is still not working for me.

Like datasage said your modal DIV id is not unique. concat your DIV id with the contact id to make each modal unique.
<div id="UpdateContact<?php echo $contact->Contacts_id ?>"
Also make sure you link your HREF the same way

Related

How to display a table using AJAX in modal?

officer_cashier.php
This is my modal form I want to display a table upon clicking the button add from cashier_template.php in DIV tag id=add_table
<div class="modal fade" id="fee_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Process payment</h5>
<button type="button" class="close get_close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" action="officer_cashier.php" id="reg">
<fieldset class="scheduler-border">
<legend class="scheduler-border">Student information</legend>
<input type="hidden" class="form-control" id="id" name="id">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" readonly="readonly">
</div>
<div class="form-group">
<label for="course">Course</label>
<input type="text" class="form-control" id="course" name="course" readonly="readonly">
</div>
<div class="form-group">
<label for="sem">Semester</label>
<input type="text" class="form-control" id="sem" name="sem" readonly="readonly">
</div>
<div class="form-group">
<label for="year">Year</label>
<input type="text" class="form-control" id="year" name="year" readonly="readonly">
</div>
</fieldset>
<button class="btn btn-sucess add_fees" id="add_fees">add</button >
<div class="form-group" id="display_table"></div><!-- I want to display the table inside of this DIV tag -->
</form>
</div>
</div>
</div>
</div>
script
This is my AJAX the course,sem,year data is what i need to display the table, so if those three fetch successfully I want to display it in my DIV tag #display_table
$(document).on('click', '.add_fees', function(){
$.ajax({
type: "post",
url: "../templates/cashier_template.php",
data: {
"course": $("#course").val(),
"semester": $("#sem").val(),
"year": $("#year").val(),
},
success: function(data) {
$("#display_table").html(data);
}
});
});
cashier_template.php
This is the cashier template once the AJAX pass the data and matcher the query it should display in modal but I wasnt getting
<?php
ob_start();
include("../include/userlogin.php");
if(!isset($_SESSION))
{
session_start();
}
if($_SESSION['usertype'] != 1){
header("location: login.php?success=1");
$_SESSION['message'] = "You cannot access this page unless you are a officer!";
}
ob_end_flush();
$yearId = $_POST['year'];
$courseId = $_POST['course'];
$semesterId = $_POST['semester'];
$result = $connect->query("SELECT id, total_fees, fee_names FROM manage_fees WHERE year_lvl = '$yearId' AND course = '$courseId' AND semester = '$semesterId'") or die($connect->error());
while($row = $result->fetch_assoc()):
?>
<div class="table-sorting table-responsive" style="margin-top: 1rem;">
<table class="table table-striped table-bordered table-hover" id="table1">
<thead>
<tr class="p-4">
<th scope="col">Select</th>
<th scope="col">School fees</th>
<th scope="col">Amount</th>
<th scope="col">type</th>
</tr>
</thead>
<tbody>
<?php
$result = $connect->query("SELECT * FROM fees;") or die($connect->error());
while($row = $result->fetch_assoc()){
?>
<tr>
<td>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input check_amount" name="local_fees">
<label class="custom-control-label" for="check_amount"></label>
</div>
</td>
<td name="selected_fees"><?php echo $row['fee_name']; ?></td>
<td name="amount"><?php echo $row['amount']; ?></td>
<td><?php echo $row['type']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php endwhile; ?>
<script src="../js/datable.js"></script>
You are overwriting the $result object (and subsequently the $row obect) when you query fees. So the big loop at the top:
while($row = $result->fetch_assoc()):
is getting overwritten down the line by
$result = $connect->query("SELECT * FROM fees;");
while($row = $result->fetch_assoc()){
But really, there's no need to query FEES in every loop. Why not first get all the fees data into an array, then just access it in the other loop. So first, at the top of your php script:
<?php
$fees=array();
$result = $connect->query("SELECT * FROM fees;");
while($row = $result->fetch_assoc()){ $fees[]=$row; }
?>
Then in your main loop
<?php
foreach ($fees as $fee) {
?>
...
<td name="selected_fees"><?php echo $fee['fee_name']; ?></td>
<td name="amount"><?php echo $fee['amount']; ?></td>
<td><?php echo $fee['type']; ?></td>
</tr>
<?php } ?>

Failing to update certain records in the database [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Well, for a good while I've now been stuck trying to figure out why most of my records are updating successfully while a certain few aren't. I've checked the php variable name/sql row names, ajax request and I don't see anything wrong. So here I am, hoping that someone can take a look at my code and help me figure out what's wrong.
Screenshot to show what I'm refering to.
Html/JS:
<div class="container">
<div class="page-header">
<h1>General Reservation
<small>Update, Delete</small>
</h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="container-fluid">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Name</th>
<th>Department/Group</th>
<th>On-site Contact</th>
<th>Phone</th>
<th>Email</th>
<th>Event Description</th>
<th>Setup Time</th>
<th>Number of Participants</th>
<th>Date</th>
<th>Start/End Time</th>
<th>Special Accommodations</th>
<th>Room</th>
<th>Room Style</th>
<th>Catering</th>
<th>Technical Equipment</th>
<th>Pre-Clean</th>
<th>On-clean</th>
<th>Post-Clean</th>
<th>Reserved Parkning</th>
<th>VIP</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/scripts.js"></script>
<script>
function viewGenData(){
$.ajax({
type: "GET",
url: "servergen.php",
success: function(data){
$('tbody').html(data);
}
});
}
function updateGenData(str){
var id = str;
var name = $('#name-'+str).val();
var dptGroup = $('#dptgroup-'+str).val();
var onSiteContact = $('#onsitecontact-'+str).val();
var phone = $('#phone-'+str).val();
var email = $('#email-'+str).val();
var eventDesc = $('#eventdesc-'+str).val();
var setUpTime = $('#setuptime-'+str).val();
var numOfParticipants = $('#partcnum-'+str).val();
var date = $('#date-'+str).val();
var startEndTime = $('#startendtime-'+str).val();
var specialAcc = $('#specialacc-'+str).val();
var room = $('#room-'+str).val();
var roomStyle = $('#roomstyle-'+str).val();
var catering = $('#catering-'+str).val();
var techEquip = $('#techequip-'+str).val();
var preClean = $('#preclean-'+str).val();
var postClean = $('#postclean-'+str).val();
var onClean = $('#onclean-'+str).val();
var rsvParking = $('#rsvparking-'+str).val();
var vip = $('#vip-'+str).val();
$.ajax({
type: "POST",
url: "servergen.php?p=edit",
data: "name=" + name + "&department=" + dptGroup + "&contact=" + onSiteContact + "&phone=" +
phone + "&email=" + email + "&description=" + eventDesc + "&setuptime=" + setUpTime + "&numberofparticipants=" + numOfParticipants +
"&date=" + date + "&startendtime=" + startEndTime + "&specialacc=" + specialAcc + "&room=" + room + "&roomstyle=" + roomStyle +
"&catering=" + catering + "&techequipment=" + techEquip + "&preclean=" + preClean + "&postclean=" + postClean + "&onclean=" + onClean +
"&rsvparking=" + rsvParking + "&vip=" + vip + "&id=" + id,
success: function(data){
viewGenData();
}
});
}
function deleteGenData(str){
var id = str;
$.ajax({
type: "GET",
url: "servergen.php?p=del",
data: "id="+id,
success: function(data){
viewGenData();
}
});
}
Php/mySQL:
<?php
include("db.php");
$page = isset($_GET['p'])?$_GET['p']:'';
if($page=='edit'){
$id = $_POST['id'];
$name = $_POST['name'];
$dptGroup = $_POST['dptgroup'];
$onSiteContact = $_POST['onsitecontact'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$eventDesc = $_POST['eventdesc'];
$setUpTime = $_POST['setuptime'];
$numOfParticipants = $_POST['partcnum'];
$date = $_POST['date'];
$startEndTime = $_POST['startendtime'];
$specialAcc = $_POST['specialacc'];
$room = $_POST['room'];
$roomStyle = $_POST['roomstyle'];
$catering = $_POST['catering'];
$techEquip = $_POST['techequip'];
$preClean = $_POST['preclean'];
$postClean = $_POST['postclean'];
$onClean = $_POST['onclean'];
$rsvParking = $_POST['rsvparking'];
$vip = $_POST['vip'];
$stmt = $db->prepare("update reservations set req_name=?, dept_group=?, onsite_contact=?, phone_num=?, email=?, event_description=?, setup_time=?, num_participants=?, date=?, start_end_time=?, notes=?, room=?, room_style=?, catering=?, tech_equip=?, pre_clean=?, post_clean=?, on_clean=?, reserved_parking=?, vip=? where id=?");
$stmt->bindParam(1,$name);
$stmt->bindParam(2,$dptGroup);
$stmt->bindParam(3,$onSiteContact);
$stmt->bindParam(4,$phone);
$stmt->bindParam(5,$email);
$stmt->bindParam(6,$eventDesc);
$stmt->bindParam(7,$setUpTime);
$stmt->bindParam(8,$numOfParticipants);
$stmt->bindParam(9,$date);
$stmt->bindParam(10,$startEndTime);
$stmt->bindParam(11,$specialAcc);
$stmt->bindParam(12,$room);
$stmt->bindParam(13,$roomStyle);
$stmt->bindParam(14,$catering);
$stmt->bindParam(15,$techEquip);
$stmt->bindParam(16,$preClean);
$stmt->bindParam(17,$postClean);
$stmt->bindParam(18,$onClean);
$stmt->bindParam(19,$rsvParking);
$stmt->bindParam(20,$vip);
$stmt->bindParam(21,$id);
if($stmt->execute()){
echo "Success, data updated.";
} else{
echo "Failed, dated not updated.";
}
} else if($page=='del'){
$id = $_GET['id'];
$stmt = $db->prepare("delete from reservations where id=?");
$stmt->bindParam(1, $id);
if($stmt->execute()){
echo "Success, data deleted.";
} else{
echo "Failed to delete data.";
}
} else{
$stmt = $db->prepare("select * from reservations order by id desc");
$stmt->execute();
while($row = $stmt->fetch()){
?>
<tr>
<td><?php echo $row['req_name']?></td>
<td><?php echo $row['dept_group']?></td>
<td><?php echo $row['onsite_contact']?></td>
<td><?php echo $row['phone_num']?></td>
<td><?php echo $row['email'] ?></td>
<td><?php echo $row['event_description'] ?></td>
<td><?php echo $row['setup_time']?></td>
<td><?php echo $row['num_participants']?></td>
<td><?php echo $row['date']?></td>
<td><?php echo $row['start_end_time']?></td>
<td><?php echo $row['notes']?></td>
<td><?php echo $row['room']?></td>
<td><?php echo $row['room_style']?></td>
<td><?php echo $row['catering']?></td>
<td><?php echo $row['tech_equip']?></td>
<td><?php echo $row['pre_clean']?></td>
<td><?php echo $row['post_clean']?></td>
<td><?php echo $row['on_clean']?></td>
<td><?php echo $row['reserved_parking']?></td>
<td><?php echo $row['vip']?></td>
<td>
<button class="btn btn-warning" data-toggle="modal" data-target="#edit-<?php echo $row['id'] ?>">Update</button>
<!-- Modal -->
<div class="modal fade" id="edit-<?php echo $row['id'] ?>" tabindex="-1" role="dialog" aria-labelledby="editLabel-<?php echo $row['id'] ?>">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="editLabel-<?php echo $row['id'] ?>">Update Data</h4>
</div>
<form>
<div class="modal-body">
<input type="hidden" id="<?php echo $row['id'] ?>" value="<?php echo $row['id'] ?>">
<div class="form-group">
<label for="name-">Name of Requestor </label>
<input type="text" class="form-control" id="name-<?php echo $row['id'] ?>" value="<?php echo $row['req_name'] ?>" />
</div>
<div class="form-group">
<label for="phone-">Phone Number</label>
<input type="tel" class="form-control" id="phone-<?php echo $row['id'] ?>" value="<?php echo $row['phone_num'] ?>"" />
</div>
<div class="form-group">
<label for="setuptime-">Facilities/Catering Set-up time
</label>
<input type="text" class="form-control" id="setuptime-<?php echo $row['id'] ?>" value="<?php echo $row['setup_time'] ?>" />
</div>
<div class="form-group">
<label for="dptgroup-">Department/Group</label>
<input type="text" class="form-control" id="dptgroup-<?php echo $row['id'] ?>" value="<?php echo $row['dept_group'] ?>" />
</div>
<div class="form-group">
<label for="email-">Email Address</label>
<input type="email" class="form-control" id="email-<?php echo $row['id'] ?>" value="<?php echo $row['email'] ?>" />
</div>
<div class="form-group">
<label for="partcnum-">Number of Participants</label>
<input type="text" class="form-control" id="partcnum-<?php echo $row['id'] ?>" value="<?php echo $row['num_participants'] ?>" />
</div>
<div class="form-group">
<label for="onsitecontact-">On-site Contact</label>
<input type="text" class="form-control" id="onsitecontact-<?php echo $row['id'] ?>" value="<?php echo $row['onsite_contact'] ?>" />
</div>
<div class="form-group">
<label for="eventdesc-">Description of the Event</label>
<textarea id="eventdesc-<?php echo $row['id'] ?>" class="form-control" rows="5" cols="25" value="<?php echo $row['event_description'] ?>"><?php echo $row['event_description']?></textarea>
</div>
<div class="form-group">
<label for="date-">Date</label>
<input type="text" class="form-control" id="date-<?php echo $row['id'] ?>" value="<?php echo $row['date'] ?>" />
</div>
<div class="form-group">
<label for="startendtime-">Start/End Time (AM/PM)</label>
<input type="text" class="form-control" id="startendtime-<?php echo $row['id'] ?>" value="<?php echo $row['start_end_time'] ?>" />
</div>
<div class="form-group">
<label for="specialacc-">Special accommodations, notes or additional requirements</label>
<textarea id="specialacc-<?php echo $row['id'] ?>" class="form-control" rows="5" cols="25" value="<?php echo $row['notes'] ?>"><?php echo $row['notes']?></textarea>
</div>
<div class="form-group">
<label for="catering-">Is catering needed?</label>
<input type="text" class="form-control" id="catering-<?php echo $row['id'] ?>" value="<?php echo $row['catering'] ?>" />
</div>
<div class="form-group">
<label for="techequip-">Is technical equipment needed?</label>
<input type="text" class="form-control" id="techequip-<?php echo $row['id'] ?>" value="<?php echo $row['tech_equip'] ?>" />
</div>
<div class="form-group">
<label for="preclean-">Is pre-clean up needed?</label>
<input type="text" class="form-control" id="preclean-<?php echo $row['id'] ?>" value="<?php echo $row['pre_clean'] ?>" />
</div>
<div class="form-group">
<label for="onclean-">Is clean up during the event needed?</label>
<input type="text" class="form-control" id="onclean-<?php echo $row['id'] ?>" value="<?php echo $row['on_clean'] ?>" />
</div>
<div class="form-group">
<label for="postclean-">Is post clean up needed?</label>
<input type="text" class="form-control" id="postclean-<?php echo $row['id'] ?>" value="<?php echo $row['post_clean'] ?>" />
</div>
<div class="form-group">
<label for="rsvparking-">Is reserved parking needed?</label>
<input type="text" class="form-control" id="rsvparking-<?php echo $row['id'] ?>" value="<?php echo $row['reserved_parking'] ?>" />
</div>
<div class="form-group">
<label for="vip">Will there be a very important person will be in attendance (dignitaries, elected officials, high profile)?</label>
<input type="text" class="form-control" id="vip-<?php echo $row['id'] ?>" value="<?php echo $row['vip'] ?>" />
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" onclick="updateGenData(<?php echo $row['id'] ?>)" class="btn btn-primary">Update</button>
</div>
</form>
</div>
</div>
</div>
<button onclick="deleteGenData(<?php echo $row['id'] ?>)" class="btn btn-danger" style="width: 73.94px; margin-top: 2px">Delete</button>
</td>
</tr>
<?php
}
}
?>
First change ajax data section from:
data: "name=" + name + "&department=" + dptGroup + "&contact=" + onSiteContact + "&phone="
to:
data: {"name": name, department: dptGroup , [...]}
Second: You will always be doing the js code from the success section. If an error occurred, send the error status, eg:
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
And last: Show yourself error messages. It should define DEBUG constant and depending on the settings display more or less information about the error.

How to get/pass the value to modal

How can I pass the value of order_id from order.php to ordermodal.php, So I can use it in my query.
This is the order.php
UI of order.php
<?php
session_start();
$order_id = $_SESSION['order_id'];
if (!isset($_SESSION['user_id']))
{
header("Location: index.php");
}
$_SESSION['navMenu'] = "order";
ini_set('display_errors', 'On');
require_once 'includes/database.php';
include_once 'system_menu.php';
include_once 'ordermodal.php';
$sql2 = "SELECT * FROM cart_tbl";
$sql = "SELECT * FROM order_tbl WHERE order_status = 'Accepted' or order_status = 'Dispatched' or order_status = 'Pending' ORDER BY order_datetime DESC";
/*** * SET UP COMBO BOX FOR SEARCH */
$comboBox = isset($_REQUEST['comboBoxVal']) ? trim($_REQUEST['comboBoxVal']) : '';
$search_by = isset($_REQUEST['search_by']) ? addslashes($_REQUEST['search_by']) : 0;
$users = null;
if ($comboBox != '') { switch ($search_by) {
case 1://Order ID
$sql .= " WHERE order_id LIKE '%{$comboBox}%' ";
break;
}
}
$carts = mysqli_query(connection(), $sql2);
$orders = mysqli_query(connection(), $sql);
$search_filters = array(1 => 'Order ID');
/*** * END SET UP COMBO BOX */ ?>
<html>
<head>
<title>ORDERS</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<style type="text/css">
body {
background:url(images/jerica.jpg)fixed no-repeat center;
background-size:cover;
}
.asd {
color: white;
}
</style>
</head>
<body>
<?php
if (isset($_SESSION['message'])) {
$message = $_SESSION['message']; unset($_SESSION['message']);
}
else {
$message = "";
}
?> <div class="container" >
<h1 class="asd">Orders</h1>
</div> <div class="container" >
<div class="panel panel-default" >
<div class="panel-heading"> <form method="post"> <div class="input-group">
<div class="input-group-addon"> <select name="search_by">
<?php
foreach ($search_filters as $key => $value): ?>
<option value="<?= $key ?>" <?= $key == $search_by ? 'selected' : '' ?> > <?= $value ?> </option>
<?php
endforeach;
?>
</select>
</div>
<input type="search" name="comboBoxVal" value="<?= $comboBox ?>" class="form-control" placeholder="Search">
</div>
</form>
</div>
<div class="panel-body">
<?php
if ($message != ''): ?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true"> ×</span></button>
<?= $message ?> </div>
<?php endif; ?>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Order ID</th>
<th>User ID</th>
<th>Order Date</th>
<th>Order Time</th>
<th>Delivery Charge</th>
<th>Total Amount</th>
<th>Address</th>
<th>Coordinates</th>
<th>Driver Number</th>
<th>Order Status</th>
<th>Action</th>
</tr>
</thead>
<?php
/*** * DISPLAY TABLE */
?>
<tbody>
<?php if ($orders): ?>
<?php
while ($order = mysqli_fetch_array($orders, MYSQLI_BOTH)):
?>
<?php
$order_datetime = $order['order_datetime'];
$date = date('Y-m-d', strtotime($order_datetime));
$time = date('H:i:s', strtotime($order_datetime));
?>
<tr>
<td><?= $order['order_id'] ?></td>
<td><?= $order['user_id'] ?></td>
<td><?= $date ?></td>
<td><?= $time ?></td>
<td><?= $order['order_deliveryCharge'] ?></td>
<td><?= $order['order_totalAmount'] ?></td>
<td><?= $order['address'] ?></td>
<td><?= $order['coordinates'] ?></td>
<td><?= $order['driver_number'] ?></td>
<td><?= $order['order_status'] ?></td>
<td><button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal" onclick="viewOrder( '<?= $order['order_id'] ?>', '<?= $order['order_id'] ?>', '<?= $date ?>', '<?= $time ?>', '<?= $order['order_deliveryCharge'] ?>', '<?= $order['order_totalAmount'] ?>', '<?= $order['address'] ?>', '<?= $order['coordinates'] ?>', '<?= $order['driver_number'] ?>', '<?= $order['order_status'] ?>')"> View Order </button>
</td>
</tr>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<div class="panel-footer">
</div>
</div>
</div>
<script>
function viewOrder(order_id, user_id, order_date, order_time, order_deliveryCharge, order_totalAmount, address, coordinates, driver_number, order_status) {
document.getElementById("titleModal").innerHTML = "viewOrder";
document.getElementsByName("order_id")[0].setAttribute("value", order_id);
document.getElementsByName("user_id")[0].setAttribute("value", user_id);
document.getElementsByName("order_date")[0].setAttribute("value", order_date);
document.getElementsByName("order_time")[0].setAttribute("value", order_time);
document.getElementsByName("order_deliveryCharge")[0].setAttribute("value", order_deliveryCharge);
document.getElementsByName("order_totalAmount")[0].setAttribute("value", order_totalAmount);
document.getElementsByName("address")[0].setAttribute("value", address);
document.getElementsByName("coordinates")[0].setAttribute("value", coordinates);
document.getElementsByName("driver_number")[0].setAttribute("value", driver_number);
document.getElementsByName("order_status")[0].setAttribute("value", order_status);
document.getElementsByName("viewOrder")[0].setAttribute("name", "viewOrder");
/*x = document.getElementsByName("order_status").value;
if(x == "Accepted"){
document.getElementsByName("submitAccept").disabled = true;
}*/
}
</script?
</body>
</html>
And this is the ordermodal.php
UI of ordermodal.php
<?php
/** *ordermodal.php **/
$id = "";
$order_date = "";
$order_time = "";
$order_id = "";
$order_deliverCharge = "";
$order_status = "";
$order_totalAmount= "";
$coordinates = "";
$driver_number = "";
$address = "";
$food_name="";
$special_request="";
$quantity="";
$amount="";
$orders="";
?>
<!-- MODALS --> <!-- DETAILS -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<form action="" method="post" class="form-horizontal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><center>×</button>
<h4 class="modal-title" id="titleModal"></h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="order_id" class="col-sm-2 control-label">Order ID</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_id" id="order_id" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="id" class="col-sm-2 control-label">ID</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="user_id" id="user_id" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_date" class="col-sm-2 control-label">Order Date</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_date" id="order_date" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_time" class="col-sm-2 control-label">Order Time</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_time" id="order_time" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_deliverCharge" class="col-sm-2 control-label">Delivery Charge</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_deliveryCharge" id="order_deliveryCharge" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_totalAmount" class="col-sm-2 control-label">Total Amount</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_totalAmount" id="order_totalAmount" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="address" class="col-sm-2 control-label">Address</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="address" id="address" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="coordinates" class="col-sm-2 control-label">Coordinates</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="coordinates" id="coordinates" placeholder="" value="" required="required" maxlength="11" readonly>
</div>
</div>
<div class="form-group">
<label for="driver_number" class="col-sm-2 control-label">Driver Number</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="driver_number" id="driver_number" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_status" class="col-sm-2 control-label">Order Status</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_status" id="order_status" placeholder="" value="" required="required" readonly>
</div>
</div>
<?php
// This is where I want to get the value of oder_id from order.php page
$sql = "SELECT food_name, special_request, quantity, amount
FROM cart_tbl
WHERE order_id=$order_id";
$result = mysqli_query(connection(), $sql);
?>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Food</th>
<th>Special Request</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
</thead>
<?php
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["food_name"];?></td>
<td><?php echo $row["special_request"];?></td>
<td><?php echo $row["quantity"];?></td>
<td><?php echo $row["amount"];?></td>
</tr>
<?php
}
}
?>
</table>
<tbody>
</div>
<div class="modal-footer">
<button type="submit" name="showOrder" id="showOrder" class="btn btn-secondary" onclick="" > Show Order </button>
<button type="submit" name="submitAccept" id="submitAccept" class="btn btn-primary" onclick="if(!confirm('Are you sure you want to accept order?')){return false;}" > Accept </button>
<button type="submit" name="submitSent" class="btn btn-primary"onclick="if(!confirm('Are you sure you want to send order?')){return false;}" >Sent</button>
<button type="submit" name="submitCancel" class="btn btn-danger" onclick="if(!confirm('Are you sure you want to cancel order?')){return false;}">Cancel</button>
<?php
if(isset($_POST['showOrder'])){
$order_id = trim(addslashes($_POST['order_id']));
}
if(isset($_POST['submitAccept'])){
$order_id = trim(addslashes($_POST['order_id']));
$query = "UPDATE order_tbl SET `order_status`='Accepted' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Accepted"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
if(isset($_POST['submitSent'])){
$order_id = trim(addslashes($_POST['order_id']));
$query = "UPDATE order_tbl SET `order_status`='Dispatched' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Dispatched"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
if(isset($_POST['submitCancel'])){
$order_id = trim(addslashes($_POST['order_id']));
$query = "UPDATE order_tbl SET `order_status`='Cancelled' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Cancelled"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
?>
</div>
</form>
</div>
</div>
</div>
So the function of this as the moment is when clicked the view order the value of the order_id from order.php didnt get, you need first to click the button inside the ordermodal.php(accept,send,cancel) in order to get the value of order_id.
"When I click the view order, I'll get right away the value of order_id so that I can use it in my sql query. This is what supposed to be the real output."
Hope you guys can help me, I stacked at this error for a couple of days already. TIA!
Couldn't you still use the session var you did in the first chunk...unless you are reseting that value - but didn't see that...
Alternatively... the url you are calling to get the url for the modal you could put a query param of OID=# and than do the typical...
$orderID = $_GET['old'] ? $_GET['old'] : $_POST['old']; // not sure if your posting or just doing a get....
Also no sure if your pulling this in through an iframe or what not but either way query param or session var should work.
Hope this helps.

Can't get values for multiple checkbox in Codeigniter (part2)

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'); .

insert multiple table rows via a php into mysql

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>

Categories