Inserting Data w/ session data into database using Codeigniter - php

Im having trouble in troubleshooting this problem, I want to save the searched data using input function and pass the id of it into the controller but im having a problem about it,
This is my Controller:
function add($id){
$this->point_m->addStudentSection($id);
redirect('admins_view/points/index');
}
This is my Model:
function addStudentSection($id){
$arr['section_id'] = $this->session->userdata('section_id');
$arr['dateadded'] = $this->input->post('dateadded');
$arr['schoolyear'] = $this->input->post('schoolyear');
$arr['semester'] = $this->input->post('semester');
$arr['point'] = $this->input->post('point');
$this->db->where('student_id',$id);
$this->db->insert('section_student',$arr);
}
in case that model above is wrong here's my other model function that i'am also using, also i am using sqlsrv for my database.
function addStudentSection($id){
$arr['section_id'] = $this->session->userdata('section_id');
$arr['dateadded'] = $this->input->post('dateadded');
$arr['schoolyear'] = $this->input->post('schoolyear');
$arr['semester'] = $this->input->post('semester');
$arr['point'] = $this->input->post('point');
$query = $this->db->query("
INSERT INTO [dbo].[section_student]
([student_id]
,[section_id]
,[dateadded]
,[schoolyear]
,[semester]
,[point])
VALUES
('$id'
,'$section_id'
,'$dateadded'
,'$schoolyear'
,'$semester'
,'$point')
");
}
so in this model i want to use also my section_id which is an session
This is my view :
<table class="table">
<tr>
<th>ID Number</th>
<th>Firstname</th>
<th>Middlename</th>
<th>Lastname</th>
<th>Total Points</th>
<th>Action</th>
</tr>
<?php
foreach ($pt as $p) {
?>
<tr>
<!-- echo query with join -->
<td><?php echo $p->idnumber ?></td>
<td><?php echo $p->firstname ?></td>
<td><?php echo $p->middlename ?></td>
<td><?php echo $p->lastname ?></td>
<td><?php echo $p->point ?></td>
<td>
Add
Redeem
</td>
</tr>
<?php
}
?>
</table>
In this table lies all the searched and retrieve datas from my display function as you can see the button to toggle is a modal.
this is my modal:
<!-- Modal -->
<form method="post" action="<?php echo base_url();?>admins/point/add">
<div class="modal fade" id="exampleModal" 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">Add Point/s</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<label>Date</label>
<input type="date" name="dateadded" class="form-control">
<label>School year</label>
<select name="schoolyear" class="form-control">
<option value="2018-2019">2018-2019</option>
<option value="2019-2020">2019-2020</option>
</select>
<label>Semester</label>
<select name="semester" class="form-control">
<option value="1st">First Semester</option>
<option value="2nd">Second Semester</option>
<option value="summer">Summer</option>
</select>
<label>Points</label>
<input type="text" name="point" class="form-control">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</form>
and this is the error response..
this is the error
Hope anyone from the community can help me,.

Because your controller add($id) expected 1 parameter, then in modal view you can't set form action like this:
<form method="post" action="<?php echo base_url();?>admins/point/add">
Change your form action to this:
<form method="post" action="<?php echo base_url();?>admins/point/add/$id">
Change $id with your parameter.
Here the docs.

you should add the id at the end of form action in your view.
or you can remove it from your function in controller and post it as a hidden input
so change your view to
<form method="post" action="<?php echo base_url();?>admins/point/add/$id">
or go to your controller and change it to
function add($id = null){
if($id == null){
$id = $this->input->post('id');
}
}
then ad a new hidden input to your view right before form close tag like this
<?php echo form_hidden('id',$the_id);?>

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 } ?>

php foreach loop editing wrong record in DB

Good day,
I've ran into a bit of a problem with my website.
I have a form which pulls a full table from my DB. Beside each record I have an 'Edit' and 'Remove' button (see image 1).
image 1
If I click on the edit button beside record 'Delete me', a modal appears and populates the value of each editable field with the current data available, and I can then edit each value and update the database. This works fine.
The problem I have; when I select one of the records where the 'Name' field is duplicated with a different 'Filling/Size' (for example, if I select 'Filling/Size' 5) it always updates and pre-populates the modal with the data from the first record in the table that shares the same 'Name'. Image 2 shows me clicking the 'Edit' button for record 1-5.
image 2
I've tried creating a foreach loop inside my foreach loop but that just duplicated every record many many times. My code is below. Any input or suggestions would be greatly appreciated.
<div class="card mb-3">
<div class="card-header">
<i class="fa fa-table"></i>Items</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" name="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Filling/Size</th>
<th>Category</th>
<th>Description</th>
<th>Price</th>
<th>Edit/Remove</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Filling/Size</th>
<th>Category</th>
<th>Description</th>
<th>Price</th>
<th>Edit/Remove</th>
</tr>
</tfoot>
<tbody>
<?php foreach ($result as $i => $row) { ?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->filling; ?></td>
<td><?php echo $row->category; ?></td>
<td><?php echo $row->description; ?></td>
<td><?php echo $row->price; ?></td>
<td id="editRemoveButtonsCell">
<button id="editButton" type="button" class="btn btn-outline-success" data-toggle="modal" data-target="#editItemModal<?php echo $row->name;?>">Edit</button>
<button id="removeButton" type="button" class="btn btn-outline-danger" data-toggle="modal" data-target="#removeItemModal<?php echo $row->name;?>">Remove</button></td>
</tr>
<!-- Delete Modal -->
<div class="modal" id="removeItemModal<?php echo $row->name;?>">
<div class="modal-dialog">
<form>
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Delete Item <?php echo $row->name?></h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
Are you sure you want to delete item <?php echo $row->name?> <?php echo $row->filling;?>? <b>This cannot be undone!</b>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<input type="hidden" value="<?php echo $row->name;?>" name="deleteItemName" id="deleteItemName">
<input type="hidden" value="<?php echo $row->filling;?>" name="deleteItemFilling" id="deleteItemFilling">
<button type="button" class="btn btn-cancel" data-dismiss="modal">Close</button>
<input type="submit" name="deleteItem" id="deleteItem" value="Delete" class="btn btn-danger" />
</div>
</div>
</form>
</div>
</div>
<!-- Edit Modal -->
<div class="modal" id="editItemModal<?php echo $row->name;?>" name="editItemModal<?php echo $row->name;?>">
<div class="modal-dialog">
<form>
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Edit Item <?php echo $row->name;?></h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="form-group">
<label for="itemNameUpdate">Name</label>
<input type="text" class="form-control" id="itemNameUpdate" name="itemNameUpdate" placeholder="Enter Item Name" value="<?php echo $row->name;?>">
<input type="hidden" value="<?php echo $row->name;?>" name="itemNameOriginal" id="itemNameOriginal">
<input type="hidden" value="<?php echo $row->filling;?>" name="itemFillingOriginal" id="itemFillingOriginal">
</div>
<div class="form-group">
<label for="itemFillingUpdate">Filling/Size</label>
<input type="text" class="form-control" id="itemFillingUpdate" name="itemFillingUpdate" placeholder="Enter Filling/Size" value="<?php echo $row->filling;?>">
</div>
<div class="form-group">
<label for="itemCategoryUpdate">Category</label>
<select class="form-control" id="itemCategoryUpdate" name="itemCategoryUpdate">
<?php echo '<option>'.$row->category.'</option>';?>
<?php foreach($categories as $category) {echo '<option>'.$category->name.'</option>';}?>
</select>
</div>
<div class="form-group">
<label for="itemDescriptionUpdate">Description</label>
<textarea class="form-control" id="itemDescriptionUpdate" name="itemDescriptionUpdate" rows="3" placeholder="Item description (optional)"><?php echo $row->description;?></textarea>
</div>
<div class="form-group">
<label for="itemPriceUpdate">Price</label>
<input type="text" class="form-control" id="itemPriceUpdate" name="itemPriceUpdate" placeholder="Enter Price" value="<?php echo $row->price;?>">
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-cancel" data-dismiss="modal">Close</button>
<input type="submit" name="editItem" id="editItem" value="Edit" class="btn btn-success" />
</div>
</div>
</form>
</div>
</div>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="card-footer small text-muted">Use the navigation bar to the left to edit the menu.</div>
</div>
</div>
All your code references are to $row->name and I would judge it to be bad practise to reference anything in the code by name. You want to be idenitifying by a unique identifier (typically a number) on each case. So you don't get this sort of ambiguity.
Image 2 shows me clicking the 'Edit' button for record 1-5.
You can't event clearly identify your own rows in this question, without needing to pull in outside data that is only co-incidentally different.
What you want is a unique identifier for each row of your database table.
This is something that is an absolute basic standard and can be read in the MySQL Dev Tutorial Here.
This SO question may also be helpful to you.
So you can update your MySQL (assuming that's your database):
ALTER TABLE users ADD uid SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
ADD INDEX (uid);
(also please see here as to which int type is best for your situation)
Once you have a unique identifier for each row, you need to then use that identifier on your code so, for example :
<input type="hidden" value="<?php echo $row->uid;?>"
name="deleteItemUniqueId" id="deleteItemUniqueId">
And
<div class="modal" id="editItemModal<?php echo $row->uid;?>"
name="editItemModal<?php echo $row->uid;?>">
And similarly apply this to your codebase throughout.
This stops any repetition of HTML ids and stops the code logic having issues with any ambiguity on the part of the identifying data given.

How to call only single row with its id in modal using php?

with table i fetch data in tabular format and with each row there is
add button.
ADD
it will open modal now i want only each rows data in modal.
<div class="modal fade" id="myModal1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<table id="name52" class="table table-striped table-bordered table-hover scroll" style="width:100%;">
<thead>
<tr>
<th>Project Name</th>
<th>Module Name</th>
<th>Actual Start Date</th>
<th>Actual End Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
$fetch =$_REQUEST['pppid'];
$sql1=mysql_query("select * from `project_assigned` where `proj_ass_id`='$fetch'");
while ( $row1 = mysql_fetch_array($sql1))
{?>
<tr>
<input required type='hidden' class='insert' value="<?php echo $row1[0]?>">
<td><?php echo get_name("add_project","project_id",$row1['project_id'],"project_name");?><input id="project_id" type="text" class="insert" value="<?php echo $row1['project_id'];?>"></td>
<td><?php echo get_name("add_project_module","module_id",$row1['module_id'],"module_name");?><input id="module_id" type="text" class="insert" value="<?php echo $row1['module_id'];?>"></td></td>
<input class="insert" type="hidden" name="" value="<?php echo $row1['emp_id'];?>">
<td><input class="controls input-group date insert" type="text" name=""></td>
<td><input class="controls input-group date insert" type="text" name=""></td>
<td><select class="insert">
<option value="In Progress">In Progress</option>
<option value="Completed">Completed</option>
</select></td>
</tr>
<?php }?>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary submit">Submit</button>
</div>
</div>
</div>
</div>
when i use this code with $fetch variable that i declare in anchor
tag it will not display that particular row.
As this request is not working for me I used another way to call ajax on ajax
page i write query and script to fetch records but its also not
working. my ajax page is working it shows data but below script for
this is not working.
<script>
$('.filter').click(function(){
var id = $(this).data('id');
alert(id);
$.ajax({url:"modal_emp_status.php"+id,cache:false,success:function(result){
alert(var str = result.split(","));
alert($("#project_id").val(str[0]));
alert($("#module_id").val(str[1]));
}});
});
</script>
my ajax page working:
<?php
include('config.php');
$sql = mysql_query("select * from `project_assigned` where `proj_ass_id`='1'");
$data = mysql_fetch_array($sql);
$str = $data['project_id'].",".$data['module_id'];
echo $str;
?>
in image you can see add button. on click add button modal will open
but i want only particular row to display in modal.
Where is your class='filter' that your jquery $('.filter') referring to? It can't be found anywhere in your html.
BTW, please read this article, mysql extension has been deprecated since php5.5.

dropdown value is not getting selected ajax html() response

I have written a dependable dropdown and its first get the id from the first dropdown and set the div id of the second drop down through ajax call. The issue is when I try to do with html() the second drop down first value can not be selected.
Here is the image of the dependable dropdown
Here is the code I am trying:
<div class="modal fade" id="addNewFloor" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
<div class="modal-dialog" role="document" style="">
<div class="modal-content">
<?php echo form_open('registrations/saveNewFloor'); ?>
<?php if (isset($message)) { ?>
<CENTER><h3 style="color:green;">Data inserted successfully</h3></CENTER><br>
<?php } ?>
<div class="modal-header">
<img src="assets/backend/img/floor.png" style="widows:50px;height:50px">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" id="myModalLabel">Register New Floor</h4>
</div>
<hr class="colorgraph">
<div id="floorModelBox"></div>
<div class="modal-body" style="margin-bottom:2px;padding-top:1px">
<table class="table table-condensed" style="background-color:#F5F5F5;margin-bottom:1px">
<caption><h3><small>Floor Path</small><h3></caption>
<!------- Select Branch --------------------->
<tr><td>Select Branch</td><td >
<select class="form-control" name="branchId_floorModel1" id="branchId_floorModel" onChange="return selectBuildings_floorModel(this.value);selectBuildings_floorModel323();clearFloors();clearSections();clearIots();clearGateways();myFunction();" >
<option value="0" selected> -- select Branch --</option>
<?php
foreach($groups as $row)
{
echo '<option value="'.$row->branchId.'">'.$row->branchName.'</option>';
}
?>
</select></td></tr>
<tr><td>Select Building</td><td>
<select class="form-control" name="buildingBox_floorModel1" style="width:100%;" id="buildingBox_floorModel" required>
<option selected ="selected" value="0">select Building</option></select>
</td></tr>
</table>
<hr/>
<table class="table table-condensed" style="margin-top:2px;margin-bottom:1px">
<caption><h3><small>Floor Details </small><h3></caption>
<tr><td>Floor Name :</td><td > <input type="text" class="form-control input-sm" name="floorName_FloorModel" id="floorName_FloorModel" /></td></tr>
<tr><td>Floor No : </td><td><input type="text" class="form-control input-sm" placeholder="building no" name="floorNo_FloorModel" id="floorNo_FloorModel" /></td></tr>
</table>
</div>
<div class="modal-footer" style="margin-bottom:2px;padding-top:1px">
<hr class="colorgraph">
<button type="button" class="btn btn-primary " data-dismiss="modal" onClick="window.location.reload();">CLOSE</button>
<?php echo form_submit(array( 'class'=>'btn btn-success ', 'id' => 'submit', 'value' => 'Submit')); ?>
<?php echo form_close(); ?><br/>
<div id="fugo">
</div>
</div>
</div>
</div>
</div>
function selectBuildings_floorModel(branchId) {
$.ajax({
url: '<?php echo base_url();?>registrations/get_building_section/' + branchId ,
success: function (response)
{
jQuery('#buildingBox_floorModel').html(response);
}
});
}
//controller method
function get_building_section($branchId)
{
$this->MBuilding->get_building_by_branch($branchId);
$sections = $this->db->get_where('building' , array(
'branchId' => $branchId
))->result_array();
// print_r($sections);die;
foreach ($sections as $row) {
//echo $row['buildingName'];
//
echo '<option value="' . $row['buildingId'] . '">' . $row['buildingName'] . '</option>';
}
}
I even tried with the append() method, but then it's not clearing the dropdown list value.
Try Following...
$("#branchId_floorModel").change(function (){
// Your Code....
});

pass a value from mysql db to bootstrap modal

i'm new to core php coding here i'm having doubt in calling a db value to bootstrap modal popup
<td class="bgimg"><?php echo $obj["service_name"]; ?></td>
this is a line used in my code to send "service_id" which from a table and it should be displayed in the modal popup, from there, user has to fill the text fields and it should be update to another table with the same id.
here is the code of modal popup
<div id="edit-modal" class = "modal fade" tabindex="-1" role="dialog" style="padding-top: 150px;" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" id="myModalLabel">Choose your slots</h4>
</div>
<div class="modal-body">
<p class="edit-content">service id:</p>
<form role="form1" name="loginform" method="post" class="login-form">
<div class="form-group">
<table align="center">
<tr>
<td colspan="2"><center>slot 1</center></td>
</tr>
<tr>
<td><input type="date" id="datePicker" name="slot1_dt"> </td>
<td><input type="time" name="slot1_tm"> </td>
</tr>
<tr>
<td colspan="2"><center>slot 2</center></td>
</tr>
<tr>
<td><input type="date" id="datePicker" name="slot2_dt"> </td>
<td><input type="time" name="slot2_tm"> </td>
</tr>
<tr>
<td colspan="2"><center><button type="submit" name="book" class="btn btn-default" value="book" style="font-size: 14px !important;">Book</button></center></td>
</tr>
</table>
<?php
if(isset($_REQUEST["book"]))
{
if($_REQUEST["book"])
{
$service_id=$_REQUEST["serv_id"];
$customer_id=$_REQUEST["cust_id"];
$slot1_dt=$_REQUEST["slot1_dt"];
$slot2_dt=$_REQUEST["slot2_dt"];
$slot1_tm=$_REQUEST["slot1_tm"];
$slot2_tm=$_REQUEST["slot2_tm"];
$slot1=$slot1_dt." ".$slot1_tm;
$slot1 = date("Y-m-d H:i:s",strtotime($slot1));
$slot2=$slot2_dt." ".$slot2_tm;
$slot2 = date("Y-m-d H:i:s",strtotime($slot2));
$insertqry="INSERT INTO `tblappointments`(`customer_id`, `service_id`, `preferred_slot1_date`, `preferred_slot2_date`) VALUES ('$customer_id','$service_id','$slot1','$slot2')";
mysqli_query($con, $insertqry) or die(mysqli_error($con));
}
}
?>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
it displays the result well but service_id is not passing to update it in the database
thanks in advance
use modal event listener,
$(document).ready(function(){
$('#edit-modal').on('show.bs.modal', function (e) {
var id = $(e.relatedTarget).attr('id');
alert(id);
$("#service_id").val(id);
});
});
and in modal in <form></form> add hidden input
<input type="hidden" id="service_id" name="serv_id" value="">
SideNote: Don't use $_REQUEST, instead use $_POST and escape the string.
$(document).on("click", "#upload_image", function () {
var myBookId = $(this).data('id');
$(".modal-body #activity_id___").val( myBookId );
console.log(myBookId);
// As pointed out in comments,
// it is superfluous to have to manually call the modal.
// $('#addBookDialog').modal('show');
});
<input type="hidden" name="activity_id___" id="activity_id___" value=""/>

Categories