Hey im still a beginner in php and im doing a detail model and i want to get the id from POST but i get this problem Notice: Undefined index: id in E:\xampp\htdocs\Site\includes\detailmodal.php on line 3
this is the function :
<script>
function details(id)
{
var data = { "id" : id };
jQuery.ajax({
url : <?= BASEURL; ?>+'includes/detailmodal.php',
method : 'POST',
data : data,
success : function(data){
$('body').append(data);
$('#details-modal').modal('toggle');
},
error : function(){
alert("something went wrong")
}
});
}
</script>
<script src="js/jquery-3.1.0.min.js" type="text/javascript"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
</body>
</html>
this is index.php :
<?php include_once 'core/init.php' ?>
<?php include 'includes/head.php' ?>
<?php include 'includes/navigation.php' ?>
<?php include 'includes/header.php' ?>
<?php include 'includes/detailmodal.php' ?>
<?php include 'includes/footer.php' ?>
<?php
$sql='SELECT * FROM products';
$featured=$db->query($sql);
?>
<!-- Body -->
<!-- Products -->
<div class="container-fluid">
<div class="col-md-2">
left side
</div>
<div class="col-md-8">
<div class="row">
<h1 class="text-center" style="color:blue; font-family: 'Orbitron', sans- serif; font-size:24px;">Products</h1><br>
<?php while ($products = mysqli_fetch_assoc($featured)): ?>
<div class="col-md-3">
<h1 class="text-center" style="color:blue; font-family: 'Orbitron', sans-serif; font-size:16px;"><?= $products["title"]?></h1>
<center> <img src="<?= $products["image"]?>" class="image-thumb" alt="Procuct1"/></center>
<p class="list-price text-danger text-center">List Price : <s><?= $products["list_price"]?></s> </p>
<p class="price text-center">Our Price : <?= $products["price"]?> </p>
<center> <button type="button" class="btn btn-sm btn-success" name="submit" onclick="details(<?php echo $products['id'];?>)">Details</button> </center>
</div>
<?php endwhile;?>
</div>
</div>
<div class="col-md-2">
right side
</div>
</div>
<!-- Modal -->
this is detailmodal.php :
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/site/core/init.php';
$id = $_POST["id"];
$id = (int)$id;
$sql = "SELECT * FROM products WHERE id = '$id'";
$result = $db->query($sql);
$products = mysqli_fetch_assoc($result);
?>
<?php ob_start(); ?>
<div class="modal fade details-1" id="details-modal" tabindex="-1" role="dialog" aria-labelledby="details-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" name="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title text-center" style="color:blue; font-family: 'Orbitron', sans-serif; font-size:40px;"><?php echo $products['title']; ?></h4>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-sm-6">
<div class="center-block">
<img src="<?php echo $products['image'];?>" alt="product1" class="details img-responsive"/>
</div>
</div>
<div class="col-sm-6">
<div class="center-block">
<h4 class="text-center" style="color:White; font-family: 'Orbitron', sans-serif; font-size:25px;">Details</h4><br><br>
<p style="color:black; font-family: 'Orbitron', sans-serif; font-size:25px;">
<?php echo $products['description'];?>
</p>
<form action="add-to-cart.php" method="post">
<div class="form-group">
<div class="col-xs-3">
<label id="quantitylbl" for="quantity">Quantity</label>
<input type="text" name="quantity" class="form-control" id="quantity" value="1" required>
</div>
<br>
<p>
available : 3
</div>
<div class="form-group">
<label id="sizelbl" for="size">Size</label>
<select name="size" id="size" class="form-control">
<option value="20">20</option>
<option value="22">22</option>
<option value="25">25</option>
</select>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" name="button">Close</button>
<button type="submit" class="btn btn-warning" name="button"><span class="glyphicon glyphicon-shopping-cart"></span>Add to Cart</button>
</div>
</div>
</div>
</div>
</div>
<?php echo ob_get_clean(); ?>
in the ajax request change the line
method : "GET"
to
method : "POST"
Also in your php file add this line after the require
if($_SERVER['REQUEST_METHOD'] == 'POST'){
and close it in the end of the code
Change the method in JQuery to POST
JQuery.ajax({
[...]
method: 'POST'
[...]
Related
my view page
<!-- BEGIN PAGE -->
<div id="main-content">
<!-- BEGIN PAGE CONTAINER-->
<div class="container-fluid">
<!-- BEGIN PAGE HEADER-->
<div class="row-fluid">
<div class="span12">
<!-- BEGIN THEME CUSTOMIZER-->
<div id="theme-change" class="hidden-phone">
<i class="icon-cogs"></i>
</div>
<!-- END THEME CUSTOMIZER-->
<!-- BEGIN PAGE TITLE & BREADCRUMB-->
<h3 class="page-title">
contactus
<small> List </small>
</h3>
<ul class="breadcrumb">
<li>
<i class="icon-home"></i><span class="divider"> </span>
</li>
<li>
Dashboard<span class="divider"> </span>
</li>
<li>
contactus <span class="divider-last"> </span>
</li>
</ul>
<br /><br />
<div id="msg">
<?php
if($this->session->tempdata('success'))
{
?>
<div class="alert alert-success hide_msg pull" style="width: 95%"> <i class="fa fa-check-circle"></i> <?php echo $this->session->tempdata('success');?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button>
</div>
<?php
}
if($this->session->tempdata('error'))
{
?>
<div class="alert alert-danger hide_msg pull" style="width: 95%"> <i class="fa fa-check-circle"></i> <?php echo $this->session->tempdata('error');?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button>
</div>
<?php
}
?>
</div>
<!-- END PAGE TITLE & BREADCRUMB-->
</div>
</div>
<!-- END PAGE HEADER-->
<!-- BEGIN PAGE CONTENT-->
<div id="page" class="dashboard">
<div class="row-fluid">
<div class="span12">
<!-- BEGIN RECENT ORDERS PORTLET-->
<div class="widget">
<div class="widget-title">
<h4><i class="icon-reorder"></i> Contactus-List </h4>
<button class="btn btn-success" style="float:right"><i class="icon-plus icon-white"></i> EXCEL </button>
</div>
<div class="widget-body">
<!-- BEGIN Table-->
<table class="table table-striped table-advance table-hover" id="sample_1">
<thead>
<tr>
<th><i class="icon_profile"></i> S.No. </th>
<th> <i class="fa fa-picture-o" aria-hidden="true"></i> Date & Time </th>
<th><i class="icon_profile"></i> Name </th>
<th> <i class="fa fa-picture-o" aria-hidden="true"></i> Email </th>
<th> <i class="fa fa-picture-o" aria-hidden="true"></i> Mobile Number </th>
<th><i class="icon_mobile"></i> Message</th>
<th><i class="icon_cogs"></i> Action</th>
</tr>
</thead>
<tbody>
<?php
$i=1;
foreach($contactus as $e)
{
?>
<tr>
<td><?php echo $i++;?></td>
<td><?php echo $e->date_and_time;?></td>
<td><?php echo $e->name;?></td>
<td><?php echo $e->email;?></td>
<td><?php echo $e->mobile_no;?></td>
<td>
<?php
$string = strip_tags($e->message);
$stringCut = substr($string, 0, 15);
echo $stringCut."...";?> click to read more
</td>
<td><div class="btn-group">
<!--<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> -->
<!-- <button class="btn btn-primary"><i class="icon-eye-open"></i></button>
<button class="btn btn-primary view" onclick="view_contact(this.value)" id="user_id" user_id="<?php echo $e->id;?>"><i class="icon-eye-open"></i></button>-->
<button class="btn btn-primary view_data" id="<?php echo $e->id; ?>" ><i class="icon-eye-open">VIEW FULL INFO</i></button>
<a onclick="return confirm('Are you want to delete ')" href="<?php echo base_url('admin/contactus_cont/delete_contactus')."/".$e->id;?>"> <button class="btn btn-danger"><i class="icon-trash icon-white"></i></button></a>
</div></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
<!-- END RECENT ORDERS PORTLET-->
</div>
</div>
</div>
<!-- END PAGE CONTENT-->
</div>
<!-- END PAGE CONTAINER-->
</div>
</div>
<!-- END CONTAINER -->
<div id="dataModal" class="modal fade">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">VIEW FULL INFO</h4>
</div>
<div class="modal-body" id="your_modal_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var id = $(this).attr("id");
//alert(id);
$.ajax({
url : "<?php echo base_url('admin/contactus_cont/get_Full_data') ?>",
method:"POST",
data:{id:id},
success:function(data){
alert(data);
//console.log(data);
$('#your_modal_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
i want to view detail about each contact by AJAX & JQUERY
in this i am getting all contact data in list from database. But the problem is to show data in pop-up in datail.
like when i click on
it should display pop-up window with all detail by using particular ID close option
my controller function :-
public function get_Full_data()
{
$id = $this->input->post("id");
//echo $id; exit;
$data['fullData'] = $this->contactus_model->view($id);
$this->load->view('admin/datainModal',$data);
}
my model function :-
public function view($id)
{
$res = $this->db->get_where("contactus",array('id'=>$id));
return $res->row();
}
view page datainModal.php :-
<div class="table-responsive">
<table class="table table-bordered">
<div class='row col-md-12'>
<div class='col-md-6'>
<tr>
<td width="30%"><label>Id</label></td>
<td width="70%"><?php echo $fullData->id;?></td>
</tr>
</div>
<div class='col-md-6'>
<tr>
<td width="30%"><label>Data & Time</label></td>
<td width="70%"><?php echo $fullData->date_and_time;?></td>
</tr>
</div>
</div>
</table>
</div>
$(document).ready(function(){
$('.view_data').click(function(){
var id = $(this).attr("id");
console.log(id);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<button class="btn btn-primary view_data" id="1" >VIEW FULL INFO</button>
View Code:
<tr>
<td>
<button class="btn btn-primary view_data" id="<?php echo $e->id; ?>" ><i class="icon-eye-open">VIEW FULL INFO</i></button>
</td>
</tr>
Bootstrap Modal Code:-
<div id="dataModal" class="modal fade">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">VIEW FULL INFO</h4>
</div>
<div class="modal-body" id="your_modal_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
JQUERY AJAX Code:-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var id = $(this).attr("id");
$.ajax({
url : "<?php echo base_url('ControllerName/get_Full_data') ?>",
type:"POST",
data:{id:id},
success:function(data){
//alert(data);
$('#your_modal_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
Controller Code:-
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class ControllerName extends CI_Controller {
public function get_Full_data(){
$id = $this->input->post("id");
$this->load->YourModelName();
$data['fullData'] = $this->YourModelName->getDatainModal($id);
$this->load->view('datainModal',$data);
}
}
?>
Modal Code:-
<?php
class YourModelName extends CI_Model {
function getDatainModal($id){
return $fullData = $this->db->get_where('table_name',array('id'=>$id))->row();
}
}
?>
Create in View datainModal.php :-
<div class="table-responsive">
<table class="table table-bordered">
<div class='row col-md-12'>
<div class='col-md-6'>
<tr>
<td width="30%"><label>Id</label></td>
<td width="70%"><?php echo $fullData->id;?></td>
</tr>
</div>
<div class='col-md-6'>
<tr>
<td width="30%"><label>Data & Time</label></td>
<td width="70%"><?php echo $fullData->date_and_time;?></td>
</tr>
</div>
</div>
</table>
</div>
I changed my web hosting server recently. After that, I realized that some parts of my jQuery code are not working. Dropdown menu not change. I checked that the old server code still now working perfectly but not on my live server.
My old server link:http://pixcelcoder.in/care-foundation/auth-admin-panel/admin-dashboard/care-class-main-chapter-list.php
New sever link:https://careonlineschool.org/care-foundation/auth-admin-panel/admin-dashboard/care-class-main-chapter-list
<?php include('header.php')?>
<!-- Main Content -->
<div class="hk-pg-wrapper">
<!-- Container -->
<div class="container mt-xl-50 mt-sm-30 mt-15">
<!-- Title -->
<div class="hk-pg-header align-items-top">
<!-- /Title -->
</div>
<div class="container">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
Add Main Chapter
</button>
<!-- Table Contain -->
<div class="container">
<br><br>
<h2>Main Chapter List </h2>
<hr>
<table class="table table-striped table-responsive w-100 d-block d-md-table">
<thead>
<tr>
<th>Class</th>
<th>Subject Name</th>
<th>Main Chapter</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$notice_query="select * FROM care_class_main_chapter";
$notice_result = mysqli_query($con,$notice_query);
while($row = mysqli_fetch_assoc($notice_result))
{
?>
<tr>
<td>
<?php
$class_name_query="select * FROM care_class INNER JOIN care_class_main_chapter ON care_class.care_class_id=care_class_main_chapter.care_class_id WHERE care_class_main_chapter.care_class_id = $row[care_class_id]";
$class_name_result = mysqli_query($con,$class_name_query);
$class_name_row=mysqli_fetch_array($class_name_result);
echo $class_name_row['care_class_number'];
?>
</td>
<td>
<?php
$subject_name_query="select * FROM care_subject INNER JOIN care_class_main_chapter ON care_subject.care_subject_id=care_class_main_chapter.care_subject_id WHERE care_class_main_chapter.care_subject_id = $row[care_subject_id]";
$subject_name_result = mysqli_query($con,$subject_name_query);
$subject_name_row=mysqli_fetch_array($subject_name_result);
echo $subject_name_row['care_subject_name'];
?>
</td>
<td><?php echo $row['care_class_main_chapter_name']; ?></td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<!-- End Table Contain -->
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Add Main Chapter</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form class="form-group" action="" method="POST">
<div class="row">
<!-- Section for Include Class -->
<div class="col-6">
<label for="Text">Class</label>
<select name="care_class_id" id="care_class_id" required>
<option value="">Select Class</option>
</select>
</div>
<!-- End Section for Include class -->
<!-- Section for Include Subject -->
<div class="col-6">
<label for="Text">Subject</label>
<select name="care_subject_id" id="care_subject_id"required>
<option value="">Select Subject</option>
</select>
</div>
<!-- End Section for Include Subject -->
</div>
<br>
<label for="class">Main Chapter</label>
<input type="text" class="form-control" placeholder="Enter Subject" name="care_class_main_chapter_name" required>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="main-chapter-add-button">Submit</button>
</form>
<?php
if(isset($_POST['main-chapter-add-button']))
{
$care_class_id=$_POST['care_class_id'];
$care_subject_id=$_POST['care_subject_id'];
$care_class_main_chapter_name=$_POST['care_class_main_chapter_name'];
$query="INSERT INTO `care_class_main_chapter` (`care_class_id`,`care_subject_id`,`care_class_main_chapter_name`) VALUES ('$care_class_id','$care_subject_id','$care_class_main_chapter_name')";
if(mysqli_query($con,$query))
{
echo '<script>swal("Main Chapter Added Sucessfully", "Please proceed", "success").then((value) => {
window.location.href="care-class-main-chapter-list.php"; });
</script>';
}
else
{
echo '<script>swal("Something Wrong", "Please proceed", "error").then((value) => {
window.location.href="care-class-main-chapter-list.php"; });
</script>';
}
}
?>
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function loadData(type,subject_id){
$.ajax({
url : "care-class-main-chapter-list-ajax.php",
type : "POST",
data:{type:type,subject:subject_id},
success : function(data){
if(type=="subject"){
$("#care_subject_id").html(data);
}
else{
$("#care_class_id").append(data);
}
}
});
}
loadData();
$("#care_class_id").on("change",function(){
var cls =$("#care_class_id").val();
loadData("subject",cls);
})
});
</script>
<!-- /Container -->
<?php include('footer.php')?>
<?php include('../../database_configuration/dbconfig.php')?>
<?php
if($_POST['type']=="")
{
$class_sql="SELECT * FROM care_class";
$class_query=mysqli_query($con,$class_sql);
$str="";
while ($row=mysqli_fetch_assoc($class_query))
{
$str.="<option value='{$row['care_class_id']}'>{$row['care_class_number']}</option>";
}
}
else if($_POST['type']=="subject")
{
$class_sql="SELECT * FROM care_subject WHERE care_class_id={$_POST['subject']} ";
$class_query=mysqli_query($con,$class_sql);
$str="";
while ($row=mysqli_fetch_assoc($class_query))
{
$str.="<option value='{$row['care_subject_id']}'>{$row['care_subject_name']}</option>";
}
}
echo $str;
?>
I am trying to make a forum, and a have made to open bootstrap modal when someone clicks on Reply Button, but that button is in while loop and modal opens only on first button in row.
This is while loop
$sql = $conn->prepare("SELECT * FROM forum_answers WHERE topicId = :id");
$sql->bindValue(":id", $id);
$sql->execute();
while($row = $sql->fetch(PDO::FETCH_ASSOC))
{
if($row['quote'] == "")
{
?>
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-md-6">
<b><?php echo $row['uid']; ?></b>
</div>
<div class="col-md-6 text-right">
<?php echo $row['date']; ?>
</div>
</div>
</div>
<div class="card-body">
<p class="card-text"><?php echo $row['answer']; ?></p>
<a class="btn btn-primary" id="btnAddReply"><i class="fas fa-fw fa-reply"></i> Reply</a>
</div>
</div>
<?php
}
else
{
?>
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-md-6">
<b><?php echo $row['uid']; ?></b>
</div>
<div class="col-md-6 text-right">
<?php echo $row['date']; ?>
</div>
</div>
</div>
<div class="card-body">
<blockquote class="blockquote" style="background-color: #F8F8F8;"><?php echo $row['quote']; ?></blockquote>
<p class="card-text"><?php echo $row['answer']; ?></p>
<a class="btn btn-primary" id="btnAddReply"><i class="fas fa-fw fa-reply"></i> Reply</a>
</div>
</div>
<?php
}
}
This is a modal.
<div class="modal fade" id="addReply" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Add Reply</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form method="post" enctype="multipart/form-data">
<div class="modal-body">
<div class="form-group">
<label for="exampleInputEmail1">Quote</label>
<?php
$sql = $conn->prepare("SELECT answer FROM forum_answers WHERE id=:id");
$sql->bindValue(":id", $id);
$sql->execute();
while($row = $sql->fetch(PDO::FETCH_ASSOC))
{
?>
<textarea class="form-control rounded-0" name="quote" id="exampleFormControlTextarea1" rows="4" disabled><?php echo $row['answer']; ?></textarea>
<?php
}
?>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Answer</label>
<textarea class="form-control" id="desc1" cols="40" rows="3" name="answer" required></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" name="submit3" value="Reply">
</div>
</form>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$("#btnAddReply").click(function() {
$("#addReply").modal();
});
});
</script>
I don't know how to use class instead id in bootstrap, I am not so great with javascript.
if you have more than one id with the same name it by default select the first one with the name when js on click event trigger in your case.
you can use jQuery like operator to trigger on click event for all the ids with name btnAddReply
<script>
$(document).ready(function() {
$("[id^=btnAddReply]").click(function() {
$("#addReply").modal();
});
});
</script>
but a clean and better solution is to use a common class. instead of id in your HTML give the class with name btnAddReply
<script>
$(document).ready(function() {
$(".btnAddReply").click(function() {
$("#addReply").modal();
});
});
</script>
Here. I have codeigniter update code, it also worked but the problem is when i click the Edit button did not parsing After space data.
(After space Words did not fetch in update model).
How can I solve this problem.
vvIncome.php view
$(document).on('click','.btn_edit', function(e) {
$("#edit").val($(this).attr('edit_id'));
$("#in_dis").val($(this).attr("in_dis"));
$("#in_amnt").val($(this).attr('in_amnt'));
$("#confirm-edit").modal({show:'true'});
});
$(document).on('click', '#btn-ys', function() {
var income_id = $('#edit').val();
var in_dis = $('#in_dis').val();
var in_amnt = $('#in_amnt').val();
var result{"income_id":income_id,"in_dis":in_dis,"in_amnt":in_amnt};
$.ajax({
data:result,
type: "POST",
url:'<?php echo base_url(); ?>admin/income/editincome/'+income_id,
success: function(data){
$("#confirm-edit").modal('hide');
viewData();
}
});
});
View PHP Code
<div class="modal fade bs-example-modal-md" id="confirm-edit" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-md" 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="myModalLabel">EDIT CATEGORY</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="well">
<form class="form-horizontal">
<div class="form-group">
<div class="col-md-12">
<input type="text"class="form-control" id="in_dis" placeholder="description">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="number" class="form-control" id="in_amnt" placeholder="amount">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="hidden" class="form-control" id="edit" placeholder="income_id">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="btn-ys" class="btn btn-success">SUBMIT</button>
</div>
</form>
</div>
</div>
</div>
</div>
`
Income_resut.php
<thead>
<tr>
<th ><center>DESCRIPTION</center></th>
<th ><center>AMOUNT</center></th>
<th ><center>EDIT</center></th>
<th ><center>DELETE</center></th>
</tr>
</thead>
<?php foreach ($incm as $in_key) { ?>
<tr>
<td><center><?php echo $in_key->description;?></center></td>
<td><center><?php echo $in_key->amount;?></center></td>
<td>
<center><button type="button" title="edit" data-toggle="modal" edit_id=<?php echo $in_key->income_id;?> in_dis=<?php echo $in_key->description;?> in_amnt=<?php echo $in_key->amount;?> class="btn btn-info btn_edit"><i class="fa fa-pencil"></i></button></center>
</td>
<td>
<center><button type="button" title="delete" data-toggle="modal" del_id=<?php echo $in_key->income_id;?> class="btn btn-danger btn-delete"><i class="fa fa-trash-o"></i></button></center>
</td>
<?php } ?>
</table>
`
income.php Controller
public function editincome($income_id)
{
$udata['income_id'] = $this->input->POST('income_id');
$udata['description'] = $this->input->POST('in_dis');
$udata['amount'] = $this->input->POST('in_amnt');
$update = $this->income_model>update_income_details($udata,$income_id);
}
Income_Model.php Model
public function update_income_details($udata,$income_id)
{
$this->db->from('income', $udata);
$this->db->where('income_id',$income_id );
return $this->db->update('income',$udata);
}
This on view table
enter image description here
This is edit model
enter image description here
Try changing to this,
for eg, in_dis=<?php echo $in_key->description;?> to data-in_dis="<?php echo rawurlencode($in_key->description); ?>"
then
$("#in_dis").val($(this).attr("in_dis")); to $("#in_dis").val(decodeURIComponent($(this).data("in_dis")));
Use .data() instead of .attr()
Let me know if it works for you.
I have a button that opens modal box. However i saved id value to that button in data-id and i want to use that value to generate content in modal box from DB.
<?php while($car = mysqli_fetch_assoc($sqlquery)) : ?>
<div class="col-md-4 text-center">
<h4><?=$car['model'];?></h4>
<img src=<?php echo $car['image'] ?>/>
<br/>
<a id="firstButton" type="button" class="show-modal btn btn-default" data-id="<?=$car['id']?>">DETAILS</a>
</div>
<?php endwhile ?>
This is how i generate the button... I need to get the data-id value somewhat to the modal box.
$(document).ready(function(){
// Otevre modal
$('.show-modal').click(function(){
var productID = $(this).attr('data-id');
//$.post('detailbox.php', {data: productID}, function(data){
// console.log(data);});
$("#itemBox").modal('show');
// kod co otevre modal, mkrni na bootstrap manual jak je otevira nebo si otevreni nadefinuj sa
$('.product_id').val(productID);
});
// Pridani do kosiku v modalu
$('.add-to-basket').click(function(){
var productID = $('.product_id').val();;
// skryty input do ktere si zapsal ID produktu po otevreni modalu
document.cookie= 'data='+productID;
$.ajax({
type: 'POST',
cache: false,
data: {id : productID},
url: 'cart/cartid.php', // tomuto souboru predas idecko produktu, zapises do kosiku atd.
success: function(data) {
window.location.replace("/shop/cart/cart.php")
alert("Product was added to basket");
// treba nejaka hlaska, ze byl pridan do kosiku
}
});
});
});
This JS gets the data-id and i can get it within input box, i tried to move the while cycle a bit down so it doesnt cycle whole modal, only the things i need to generate, but i cannot get data from input box that i need.
?php while($details = mysqli_fetch_assoc($sqlquery)) : ?>
<div class="container">
<!-- Modal -->
<div class="modal fade" id="itemBox" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body display-content">
<div class="container-fluid">
<div class="col-md-4"><img src=<?php echo $details['image'];?> class="image-responsive">
<div class="col-sm-6">
<form action="add_cart.php" method="post">
<div class="form-group">
<label for="quantity">Quantity:</label>
<input type="text" class="form-control" id="quantity" name="quantity">
</div>
</form>
</div>
<div class="col-sm-6">
<br/>
<!-- Getting product ID from JS, -->
<div class="product_id">
<input class="product_id" type="text" id="input_product_id" name="input_product_id" value=""/>
</div>
<button type="button" class="add-to-basket btn btn-success" >ADD TO CART</button>
</div>
</div>
<div class="col-md-1"></div>
<div class="col-md-7" id="desc">
<p><b>Model:</b> <?php echo $details['model'];?></p>
<p><b>Engine:</b> <?php echo $details['engine'];?></p>
<h4>Description</h4>
<p><?php echo $details['description'];?></p>
<hr>
<hr>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>