inline form working fine chrome but not in mozila - php

Here is my code,it is working fine on chrome but not on mozila.I tried but i don't understand why is it not working.Thanks in advance for your help.
<div class="page-content">
<div class="page-header">
<h1>Add new report</h1>
</div><!-- /.page-header -->
<?php
if ( isset($msg) && $msg != null ){
if ( isset( $msg_type ) && $msg_type != null ){
$alert_type = 'alert-'.$msg_type;
}else{
$alert_type = 'alert-info';
}
?>
<div class="alert <?php echo $alert_type;?>">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<?php echo $msg;?>
</div>
<?php
}
?>
<div class="row">
<div class="col-xs-10 col-sm-10 col-md-10">
<!-- PAGE CONTENT BEGINS -->
<div class="table-responsive">
<form name="prof" action="<?php echo base_url();?>addrep" method="post" class="form-horizontal" role="form" enctype="multipart/form-data">
<div class="form-group">
<label class="col-xs-3 col-sm-3 col-md-3 control-label">Select network:</label>
<div class="col-xs-3 col-sm-3 col-md-3">
<select name="nid" class="form-control input_sm" id="nid">
<option value="">Select network</option>
<?php foreach( $networks as $network ): ?>
<option value="<?php echo $network->net_id;?>"><?php echo $network->net_name;?></option>
<?php error_log($network->net_id);?>
<?php endforeach; ?>
</select>
<button class="btn btn-primary btn-xs new_bm" data-toggle="modal" data-target=".add_net" id="">Add Network</button>
</div>
</div>
<div class="form-group">
<label class="col-xs-3 col-sm-3 col-md-3 control-label">Select network element:</label>
<div class="col-xs-5 col-sm-5 col-md-5">
<select name="ne" class="form-control input_sm" id="ne">
<option value="">Select network element</option>
<?php foreach( $ners as $ne ): ?>
<option value="<?php echo $ne->ne_name;?>"><?php echo $ne->ne_name;?></option>
<?php error_log($ne->ne_name);?>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-xs-3 col-sm-3 col-md-3 control-label">Select report type:</label>
<div class="col-xs-5 col-sm-5 col-md-5">
<select name="rt" class="form-control input_sm" id="rt">
<option value="">Select report type</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-xs-3 col-sm-3 col-md-3 control-label">Enter report name:</label>
<div class="col-xs-5 col-md-5 col-sm-5">
<input type="text" name="rep_name" id="rep_name" placeholder="Enter report name" />
</div>
</div>
<div class="col-sm-offset-4 col-md-offset-4 col-xs-offset-4">
<button type="submit" class="btn btn-primary" name="submit-buttons" id="submit-buttons" value="add">Add</button>
<button type="submit" class="btn btn-primary" name="submit-buttons" id="submit-buttons" value="cancel">Cancel</button>
</div>
</form>
</div>
<div class="modal fade add_net" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<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="modalLabel">Add Network</h4>
</div>
<div class="modal-body">
<form role="form" class="form-inline" action="addnet" method="post">
<div class="form-group">
<h4>Network name</h4>
<input type="text" value="" name="net" id="net" class="form-control" placeholder="New name" />
</div>
<div>
<input type="submit" value="Add" class="btn btn-primary btn-xs" />
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
</div>
</div>
<script>
$( "#ne" ).change(function(){
var options = [];
options.push( '<option value="', '', '">', 'Select report type', '</option>' );
$( "#rt > option" ).remove();
$.ajax({
type : 'POST',
url : 'grtbne',
data: 'ne='+$(this).val(),
dataType: 'json',
success : function(result){
$.each ( result, function (key , value){
options.push( '<option value="', value.report_type, '">', value.report_type, '</option>' );
});
$( "#rt" ).html( options.join( '' ) );
},
});
});
</script>
here,ajax is used for dynamically loading the selected item.

$.each is the problem not working on firefox. Please try to change that to a for loop may be or any other alternative should work.

Related

Undefined variable even I defined it [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 3 years ago.
[20-Mar-2019 04:24:48 America/New_York] PHP Notice: Undefined variable: start_date in /home/wwwrsfcrm/public_html/airportextras/admin/advance-settings.php on line 244
[20-Mar-2019 04:24:48 America/New_York] PHP Notice: Undefined variable: end_date in /home/wwwrsfcrm/public_html/airportextras/admin/advance-settings.php on line 246
Here is my code
<?php include('inc/header.php'); ?>
<?PHP
session_start();
if($_SESSION['username']=='' && $_SESSION['password']==''){
header('Location: index');
}
?>
<?php include('inc/sidebar.php'); ?>
<?php
$currentid = $_SESSION['aid'];
$con = mysqli_connect("localhost","root","password","database");
//Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "SELECT * FROM disabled_dates WHERE agent_id = '$currentid'";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$start_date = $row['start_date'];
$end_date = $row['end_date'];
}
}
?>
<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">
<div class="row">
<ol class="breadcrumb">
<li><svg class="glyph stroked home"><use xlink:href="#stroked-home"></use></svg></li>
<li class="active">Icons</li>
</ol>
</div><!--/.row-->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header"></h1></h1>
</div>
</div><!--/.row-->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">Airport Parking Advance Settings</div>
<div class="panel-body">
<div class="col-md-12">
<button class="btn btn-primary" data-toggle="modal" data-target="#cpbd" id="link_bt">Change Price by Date</button>
<button class="btn btn-primary" data-toggle="modal" data-target="#soobd" id="link_bt">Service Disable by Date</button>
<!--Change Price by Date Modal -->
<div id="cpbd" class="modal fade" role="dialog">
<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">Change Prices by Date</h4>
</div>
<div class="modal-body">
<p>
<form role="form" method="post" action="changed-prices" id="sign_in" autocomplete="off">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="form-group plates-options">
<label>Change Prices by Date</label>
<input type="date" id="check_out" name="sdate" placeholder="Date" class="form-control" aria-required="true" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Day Price</label>
<input name="dayprice" type="text" class="form-control" placeholder="Day Price" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Additional Day Price</label>
<input name="addprice" type="text" class="form-control" placeholder="Additional Day Price" required>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<h3>Prices for Meet & Greet</h3>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Fixed Price</label>
<input name="mgfixprice" type="text" class="form-control" placeholder="Fixed Price" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Flexible Price</label>
<input name="mgflexprice" type="text" class="form-control" placeholder="Flexible Price" required>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<h3>Prices for Park & Ride</h3>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Fixed Price</label>
<input name="prfixprice" type="text" class="form-control" placeholder="Fixed Price" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Flexible Price</label>
<input name="prflexprice" type="text" class="form-control" placeholder="Flexible Price" required>
</div>
</div>
</div><!-- End row -->
<div class="row">
<div class="col-md-12 col-sm-12">
<div class="form-group">
<input type="submit" name="pricedate" value="Submit" class="btn btn-primary" id="price-date">
</div>
</div>
</div>
</form>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--Add Off Hours to take booking Modal -->
<div id="soobd" class="modal fade" role="dialog">
<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">Service Disable by Date</h4>
</div>
<div class="modal-body">
<p>
<form role="form" method="post" action="service-disable" id="sign_in" autocomplete="off">
<div class="row">
<h3>Service Disable by Date</h3>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group plates-options">
<label>Start Date</label>
<input class="form-control" data-date-format="M d, D" type="date" name="sdate" placeholder="Date" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group plates-options">
<label>End Date</label>
<input class="form-control" data-date-format="M d, D" type="date" name="edate" placeholder="Date" required>
</div>
</div>
</div><!-- End row -->
<div class="row">
<div class="col-md-12 col-sm-12">
<div class="form-group">
<input type="submit" name="specificdate" value="Submit" class="btn btn-primary" id="hours">
</div>
</div>
</div>
</form>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div> <br><br>
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<h3>Your Service's Disable Dates </h3>
<tbody>
</tr>
<tr>
<th>Start Date</th>
<th>End Date</th>
</tr>
<tr>
<td> <?php echo $start_date; ?> </td>
<td> <?php echo $end_date; ?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div><!-- /.col-->
</div><!-- /.row -->
</div><!--/.main-->
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/chart.min.js"></script>
<script src="js/chart-data.js"></script>
<script src="js/easypiechart.js"></script>
<script src="js/easypiechart-data.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/pepper-grinder/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.js"></script>
<form name="select-multiple">
<script>
$("#addday").change(function () {
$("#adddayprice").toggle();
});
$("#mg").change(function () {
$("#mgprice").toggle();
$("#mgprice2").toggle();
});
$("#pr").change(function () {
$("#prprice").toggle();
$("#prprice2").toggle();
});
!function ($) {
$(document).on("click","ul.nav li.parent > a > span.icon", function(){
$(this).find('em:first').toggleClass("glyphicon-minus");
});
$(".sidebar span.icon").find('em:first').addClass("glyphicon-plus");
}(window.jQuery);
$(window).on('resize', function () {
if ($(window).width() > 768) $('#sidebar-collapse').collapse('show')
})
$(window).on('resize', function () {
if ($(window).width() <= 767) $('#sidebar-collapse').collapse('hide')
})
</script>
</body>
</html>
Solution 1 :
Before the While/if/else :
$start_date = $end_date = NULL;
In the html :
<?php echo (!empty($end_date))?$end_date:"0000/00/00"; ?>
//same with start_date
//or
<?php if(!empty($end_date)){
echo $end_date;
}else{
echo "0000/00/00";
}?>
Solution 2 :
Only in the html :
<?php echo (isset($end_date))?$end_date:"0000/00/00"; ?>
//same with start_date

Insert query inside a modal

I would like to ask for some assistance when it comes to inserting details into mysql database if data are inside a modal. I have been trying to complete this sample project of mine hoping that I can use it as a portfolio in the future. Here's the modal code.
main.php
<div class="modal fade" id="registrationModalold" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<!--<form action="functions/actions.php" method="POST">-->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Enrollment Details</h4>
</div>
<div class="modal-body">
<form method="post" action="functions/actions.php">
<h4 class="modal-title">Personal Information</h4>
<div class="row">
<div class="col-lg-6 col-xs-6">
<label for="usr">Name:</label>
<select class="form-control" name="courses">
<?php
include 'ini/db.php'; //connect to database
$sql = "SELECT distinct student_name FROM tbl_students";
$res = mysqli_query($conn,$sql);
echo "<option>---SELECT STUDENT---</option>";
while ($row = mysqli_fetch_array($res)){
echo "<option value=Course".$row['student_name'].">" . $row['student_name'] . "</option>";
}
?>
</select>
</div><!-- ./col -->
<div class="col-lg-6 col-xs-6">
<label for="usr">Addres:</label>
<input type="text" class="form-control" id="fullname">
</div><!-- ./col -->
</div>
<div class="row">
<div class="col-lg-3 col-xs-6">
<label for="usr">Contact:</label>
<input type="text" class="form-control" id="fullname">
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<label for="usr">BirthDate:</label>
<input type="text" class="form-control" id="fullname">
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<label for="usr">Birth Place:</label>
<input type="text" class="form-control" id="fullname">
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<label for="usr">Gender:</label>
<select class="form-control">
<option id="male">Male</option>
<option id="female">Female</option>
</select>
</div><!-- ./col -->
</div>
</br></br>
<h4 class="modal-title">Other Information</h4>
<div class="row">
<div class="col-lg-6 col-xs-6">
<label for="usr">Course:</label>
<select class="form-control" name="courses">
<?php
include 'ini/db.php'; //connect to database
$sql = "SELECT crs_id,crs_name FROM tbl_courses";
$res = mysqli_query($conn,$sql);
echo "<option>---SELECT COURSE---</option>";
while ($row = mysqli_fetch_array($res)){
echo "<option value=Course".$row['crs_id'].">" . $row['crs_name'] . "</option>";
}
?>
</select>
</div><!-- ./col -->
<div class="col-lg-6 col-xs-6">
<label for="usr">Major:&nbsp<font color="red" size="2"><i>optional</i></font></label>
<input type="text" class="form-control" id="fullname">
</div><!-- ./col -->
</div>
<div class="row">
<div class="col-lg-3 col-xs-6">
<label for="usr">Mother's Name:</label>
<input type="text" class="form-control" id="fullname">
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<label for="usr">Mother's Occupation:</label>
<input type="text" class="form-control" id="fullname">
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<label for="usr">Father's Name:</label>
<input type="text" class="form-control" id="fullname">
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<label for="usr">Father's Occupation:</label>
<input type="text" class="form-control" id="fullname">
</div><!-- ./col -->
</div>
</div>
<div class="modal-footer">
<button name="btnregister" action="functions/actions.php" type="button" class="btn btn-default">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
</div>
As you can see there's a button there a button which points to my actions.php which is inside another folder which is functions folder. But when I click that nothing happens.
Here's the action.php:
if (isset($_POST['btnregisters'])) {
echo "ASASASASASASASASASASAS";
die("asdsadsada");
}
As you can see there's a button there a button which points to my actions.php which is inside another folder which is functions folder. But when I click that nothing happens
<button name="btnregister" action="functions/actions.php" type="button" class="btn btn-default">Save</button>
You said type="button". The entire point of that is to make the button do nothing (so you can bind JavaScript event handlers to it).
Take that out and let it be the default (type="submit") which would submit the form.
Please see that the submit button is set as button type = "button"
<button name="btnregister" action="functions/actions.php" type="button" class="btn btn-default">Save</button>
Change it to:
<button name="btnregister" action="functions/actions.php" type="submit" class="btn btn-default">Save</button>
You have already defined action attribute in form tag. action attributes are not for buttons so do not write it there.
To submit a form you need a submit button so, change type of your save button from "button" to "submit"
it should be like
<button name="btnregister" type="submit" class="btn btn-default">Save</button>

Button isn't fired in a Modal

I'm using an "a" to call a modal:
ausencias.php
echo ' <i class="fa fa-pencil"></i>';
edit.php:
<html>
<?php
If(isset($_GET['aus'])) {
//BASE DE DADOS
include("connection.php");
$aprovar=$_GET['aus'];
$resultado=mysqli_query($db, "SELECT *
FROM contas as a, ausencia as h
WHERE a.id = h.id
AND h.idausensia='$aprovar'");
while($row = mysqli_fetch_array($resultado)){
$noome=$row['nome'];
$pic=$row['pic'];
$datasaida=$row['datasaida'];
$datavolta=$row['datavolta'];
$motivo=$row['tipos'];
$ficheiro=$row['justfile'];
}
?>
<div id="custom-content" class="modal-block modal-block-md">
<section class="panel">
<header class="panel-heading">
<h2 class="panel-title">Visualização de Pedido de Ausência - <?php echo($noome)?> </h2>
</header>
<div class="panel-body">
<div class="row">
<div class="col-md-3">
<br>
<center><img class="img-responsive" src="<?php echo($pic) ?>" /></center>
<br>
</div>
<div class="col-md-22">
</div>
</div>
<div class="row">
<div class="col-md-40">
<div class="panel-body">
<div class="form-group">
<label class="col-md-3 control-label" for="inputReadOnly">Nome</label>
<div class="col-md-6">
<input type="text" value="<?php echo($noome) ?>" id="inputReadOnly" class="form-control" readonly="readonly">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="inputReadOnly">Comprovativo</label>
<div class="col-md-6">
<a class="mb-xs mt-xs mr-xs btn btn-primary" href='download.php?down=<?php echo($ficheiro)?>'><i class="fa fa-cloud"></i> Baixar</a>
</div>
<br><br>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="inputReadOnly">Motivo</label>
<div class="col-md-6">
<input type="text" value="<?php echo($motivo) ?>" id="inputReadOnly" class="form-control" readonly="readonly">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="inputReadOnly">Inicio Ausência</label>
<div class="col-md-6">
<input type="text" value="<?php echo($datasaida) ?>" id="inputReadOnly" class="form-control" readonly="readonly">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="inputReadOnly">Fim Ausência</label>
<div class="col-md-6">
<input type="text" value="<?php echo($datavolta) ?>" id="inputReadOnly" class="form-control" readonly="readonly">
</div>
</div>
<br>
<br>
<footer class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<form action="" method="post">
<input type="submit" value="Test" name="confirmar">
<button class="btn btn-default modal-dismiss">Sair</button>
<button name="recusar" type="button" class="mb-xs mt-xs mr-xs btn btn-danger">Recusar</button>
</form>
</div>
</div>
</footer>
</div>
</div>
</div>
</div>
<?php
if(isset($_POST['confirmar'])){
mysqli_query($db, "UPDATE ausencia SET estados='Rascunho' WHERE idausensia='$aprovar'");
mysqli_close($db);
header("Location: ausencias.php");
}
?>
<footer class="panel-footer">
<div class="row">
<div class="col-md-12 text-right">
</div>
</div>
</footer>
</section>
</div>
<?php }?>
<html>
But for some reason, the Isset is not working for the button, but when i remove the If, the SQL statement works. When i click the button it just close the modal and don't trigger what is inside the If.
Can anyone help me?
the if that dont work is that:
if(isset($_POST['confirmar'])){
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<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">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
you are adding direct php file in href of anchor it will redirect you on target page use Simply Modal window of Bootstrap.

how to set value in input type = file from database

<div class="modal fade validate" id="modal-6">
<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">Edit Advertisement</h4>
<label class="idhere"><?php echo $id; ?></label>
</div>
<?php $sel = $d->select('advertisements', 'ad_id=12');
while ($result = mysqli_fetch_assoc($sel)) {
?>
<div class="modal-body">
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Image Upload</label>
<div>
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail" style="width: 200px; height: 150px;" data-trigger="fileinput">
<img src="<?php echo $result['photo']; ?>">
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px"></div>
<div>
<span class="btn btn-white btn-file">
<span class="fileinput-new">Select image</span>
<span class="fileinput-exists">Change</span>
<input type="file" name="advertise_photo" accept="image/*">
</span>
Remove
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info">Send</button>
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>
<?php } ?>
</div>
</div>
</div>
I am unable to set the value of input type=file from database,
and if the image is exits then change button appear instead of select image.
when i am choosing new file it works properly,and change and remove button appear instead of select file.
Please help me to solve it.
Note: Above question is continuous of this question so the following answer is also continuous of this answer
You can skip the <label class="idhere"><?php echo $id;?></label>
in JS what yo need is ajax call method to fetch data from database against <?php $id;?> and display in modal
$(document).ready(function() {
$('#modal-6').on('shown.bs.modal', function(e) {
var id = $(e.relatedTarget).data('id');
$.ajax({
type : 'post',
url : 'file.php', //Here you will fetch records or images
data : 'id='+ id, //Pass id
success : function(data){
$('#fetched-data').html(data);//Show fetched data from database
}
});
});
});
Modal HTML will be
<div class="modal fade validate" id="modal-6">
<div class="modal-dialog">
<div class="modal-content">
<div id="fetched-data"></div>
</div>
</div>
</div>
and file.php will be
<?php
//database connection
if($_POST['id']) {
$id = $_POST['id']; //escape the string
//run query
//fetch data from database
//poplutae the HTML with values
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Edit Advertisement</h4>
</div>
<?php $sel = $d->select('advertisements','ad_id=12');
while($result = mysqli_fetch_assoc($sel)){
?>
<div class="modal-body">
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Title</label>
<input class="form-control" value="<?php echo $result['title'];?>" name="advertise_title" data-validate="required" data-message-required="Please Enter Title" placeholder="Enter Title" type="text">
</div>
<div class="form-group col-md-6">
<label class="control-label">URL</label>
<input class="form-control" name="advertise_url" value="<?php echo $result['url'];?>" data-validate="required" data-message-required="Please Enter URL" placeholder="Enter URL" type="text">
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group no-margin">
<label for="description" class="control-label">Description</label>
<textarea class="form-control autogrow" id="description" name="advertise_desc" placeholder="Describe Description Regarding Query">
<?php echo trim($result['description']); ?>
</textarea>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Image Upload</label>
<div>
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail" style="width: 200px; height: 150px;" data-trigger="fileinput">
<img src="<?php echo $result['photo']; ?>">
<!-- <img src="images/thumbnail.jpeg" alt="..."> -->
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px"></div>
<div>
<span class="btn btn-white btn-file">
<span class="fileinput-new">Select image</span>
<span class="fileinput-exists">Change</span>
<input type="file" name="advertise_photo" accept="image/*" >
</span>
Remove
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Active Flag</label>
<input type="checkbox">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info">Send</button>
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>
<?php } } ?>
As suggested by #devpro you need <form></form> to edit / update the populated data inside modal.

Records not saving into database when saving from bootstrap modal pop up in php

I want to submit data in database using bootstrap modal popup but when i press submit buttons nothing happens and i think that page which is used to submit a record is also not called. Below is the code of modal popup: i have called addProducts.php page but it is not called on click of a submit buttom please help to solve it. Thanks..
<div class="modal fade" id="myModal">
<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">Add Products Details</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-lg-12">
<form role="form" name="Insertdb" method="post" action="Insert_code/add-products.php">
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>Product Name</label>
</div>
</div>
<div class="col-lg-6">
<input class="form-control" name="prodName" placeholder="Enter product Name">
</div>
</div>
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>Product Price</label>
</div>
</div>
<div class="col-lg-6">
<input class="form-control" name="prodPrice" placeholder="Enter product price">
</div>
</div>
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>Product Type</label>
</div>
</div>
<div class="col-lg-6">
<input class="form-control" name="productType" placeholder="Enter product type">
</div>
</div>
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>Product Description</label>
</div>
</div>
<div class="col-lg-6">
<textarea class="form-control" name="productDesc" rows="3"></textarea>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input name="button1" type="submit" class="btn btn-primary">
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</div>
<?
require_once('user.inc.php');
$Users = new Users();
$name=$_REQUEST['prodName'];
$price=$_REQUEST['prodPrice'];
$type=$_REQUEST['productType'];
$description=$_REQUEST['productDesc'];
$query="INSERT INTO tbl_product(`product_name`,`product_desc`,`product_price`,`product_type`)
VALUES('".$name."','".$description."','".$price."','".$type."')";
if(!executeQuery($query))
{
echo '<script language="javascript">';
echo 'alert("An error occured. Please try again")';
echo '</script>';
else
{
echo '<script language="javascript">';
echo 'alert("Record Successfully Inserted")';
echo '</script>';
}
?>

Categories