I am trying to echo a bootstrap modal with php . I have some data from table database and if I click on button and try to echo modal on If(isset) condition, the modal is not showing.
see my Code Here:
<?php
//insert in persnaol user table
$sql = "SELECT id,date,status FROM $x order by id DESC;";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<div class='border'> ";
echo "";
echo "<form action='#' method='POST'>";
$id = $row['id'];
echo "<input type='show' name='statusid' value='$id' >";
echo "<p> " . $row["status"] ."</p><br>";
echo "<a class='pull-right' ><input type='submit' value='Edit Post' class='btn1' name='editbtn' data-toggle='modal' data-target='#qModal' ></a>";
echo "<small> " . $row["date"]. "</small><br>";
$editid= $row['id'];
echo "</form><br>";
echo "</div>";
echo "<br>";
echo'
<script>
$("form").submit(function(e){
e.preventDefault();
});
</script>';
}
} else {
echo "hello";
}
?>
and my modal html code is here. modal window is not established.
<?php
require'db.php';
if(isset($_POST['editbtn'])){
$x = $_SESSION['username'];
$id=$_POST["statusid"];
echo '<div class="modal fade" id="qModal" role="dialog" >';
echo ' <div class="modal-dialog" style="z-index:1000;">';
echo '<div class="modal-content">';
echo '<div class="modal-header">';
echo ' <button type="button" class="close" data-dismiss="modal">×</button>';
echo ' <h4 class="modal-title">Post Editing.</h4>';
echo ' </div>';
echo ' <div class="modal-body">';
echo ' <P>';
echo $id;
echo '</p>';
echo ' <form>';
echo ' <textarea value="" >hello</textarea>';
echo ' </form>';
echo '</div>';
echo ' <div class="modal-footer">';
echo ' <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';
echo ' </div> </div> </div> </div>';
}
?>
Your form is actually submited so you should see the screen blinking, modal display but the page is reloaded.
To prevent this you can prevent the default form submit action with jQuery for example or remove your form.
As you have Bootstrap activated for your modal I assume you also have jQuery, try to add this at the end of your php script:
echo'
<script>
$("form").submit(function(e){
e.preventDefault();
});
</script>';
EDIT1:
I made a test file and It works for me, here is what's in my file:
<?php
echo '
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>';
$id=7;
echo '<div class="modal fade" id="qModal" role="dialog" >';
echo ' <div class="modal-dialog" style="z-index:1000;">';
echo '<div class="modal-content">';
echo '<div class="modal-header">';
echo ' <button type="button" class="close" data-dismiss="modal">×</button>';
echo ' <h4 class="modal-title">Post Editing.</h4>';
echo ' </div>';
echo ' <div class="modal-body">';
echo ' <P>';
echo $id;
echo '</p>';
echo ' <form>';
echo ' <textarea value="" >hello</textarea>';
echo ' </form>';
echo '</div>';
echo ' <div class="modal-footer">';
echo ' <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';
echo ' </div> </div> </div> </div>';
echo "<div class='border'> ";
echo "";
echo "<form action='#' method='POST'>";
$id = 2;
echo "<input type='show' name='statusid' value='$id' >";
echo "<p> " . "here" ."</p><br>";
//**edit button is here**
echo "<a class='pull-right' ><input type='submit' value='Edit Post' class='btn1' name='editbtn' data-toggle='modal' data-target='#qModal' ></a>";
echo "<small> " . "date". "</small><br>";
$editid= 2;
echo "</form><br>";
echo "</div>";
echo "<br>";
echo'
<script>
$("form").submit(function(e){
e.preventDefault();
});
</script>';
Related
I'm looking for a simple solution to inserting multiple checkbox selections into a single database column. If user selects 3 x l_comp checkboxes - the database should reflect "result, result, result".. the commas would be nice but are not neccessary.
As it is, if one checkbox is selected, the information will insert as it should. If multiple are selected, only the last one will be inserted into the DB. Everything else is working fine, but these darned checkboxes!
I know i'm vulnerable to sql-injection
My code:
<?php
// Initialize the session
session_start();
// Include config file
require_once "assets/scripts/config.php";
$param_uniqid = $_SESSION['uniqid'];
$param_company = $_SESSION['company'];
$param_vat = $_SESSION['vat'];
$param_username = $_SESSION['username'];
// Check if the user is logged in, if not then redirect him
to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"]
!== true){
header("location: login.php");
exit;
}
// Define variables and initialize with empty values
$l_comp = $user = $car = $uniqid = $company = $vat =
$username = "";
$l_comp_err = $user_err = $car_err = $uniqid_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate l_comp
$input_l_comp = trim($_POST["l_comp"]);
if(empty($input_l_comp)){
$l_comp_err = "Venligst indtast leasingselskab.";
} elseif(!filter_var($input_l_comp, FILTER_VALIDATE_REGEXP,
array("options"=>array("regexp"=>"/^[0-9a-åA-Å+&##\/%-?
=~_|!:,.;\s]+$/")))){
$l_comp_err = "Leasingselskab er ikke korrekt.";
} else{
$l_comp = $input_l_comp;
}
// Validate user
$input_user = trim($_POST["user"]);
if(empty($input_user)){
$user_err = "Venligst indtast en bruger.";
} elseif(!filter_var($input_user, FILTER_VALIDATE_REGEXP,
array("options"=>array("regexp"=>"/^[0-9a-åA-Å\s]+$/")))){
$user_err = "Bruger er ikke korrekt.";
} else{
$user = $input_user;
}
// Validate car
$input_car = trim($_POST["car"]);
if(empty($input_car)){
$car_err = "Venligst indtast bilinformationer.";
} elseif(!filter_var($input_car, FILTER_VALIDATE_REGEXP,
array("options"=>array("regexp"=>"/^[0-9a-åA-Å+&##\/%-?
=~_|!:,.;\s]+$/")))){
$car_err = "Bil er ikke korrekt.";
} else{
$car = $input_car;
}
// Validate uniqid
$input_uniqid = trim($_POST["uniqid"]);
if(empty($input_uniqid)){
$uniqid_err = "Venligst indtast uniqid.";
} elseif(!filter_var($input_uniqid, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[0-9a-åA-Å+&##\/%-?=~_|!:,.;\s]+$/")))){
$uniqid_err = "Uniqid er ikke korrekt.";
} else{
$uniqid = $input_uniqid;
}
// Check input errors before inserting in database
if(empty($l_comp_err) && empty($user_err) && empty($car_err)
&& empty($uniqid_err)){
// Prepare an insert statement
$sql = "INSERT INTO offer_requests_test (l_comp, user,
car, uniqid, company, vat, username) VALUES (?, ?, ?, ?, ?,
?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as
parameters
mysqli_stmt_bind_param($stmt, "sssssss",
$param_l_comp, $param_user, $param_car, $param_uniqid,
$param_company, $param_vat, $param_username);
// Set parameters
$param_l_comp = $l_comp;
$param_user = $user;
$param_car = $car;
$param_uniqid = $uniqid;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Records created successfully. Redirect to
landing page
header("location: /offer_requests_test");
exit();
} else{
echo "Something went wrong. Please try again
later.";
}
}
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Fleets - få op til 3 tilbud på jeres næste
leasingbil</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="assets/css/main.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
</head>
<body class="subpage">
<!-- Header -->
<header id="header">
<div class="logo">Fleets.dk <span>3 tilbud på leasingbil</span></div>
LOG UD
</header>
<!-- content -->
<div class="box">
<div class="inner">
<div class="content">
<h4>Hej, <b><?php echo htmlspecialchars($_SESSION["name"]); ?></b>.</h4>
<hr />
<ul class="nav nav-tabs">
<li role="presentation">Profil</li>
<li role="presentation">Biler</li>
<li role="presentation" class="active">Tilbud</li>
<li role="presentation">Kontakter</li>
</ul>
<div class="table-wrapper">
<h4 class="pull-left">Oprettede tilbud</h4>
<table>
<tbody>
<tr>
<th class="hidden"><b>#</b></th>
<th><b>Bil</b></th>
<th><b>Bruger</b></th>
<?php
// Include config file
require_once "assets/scripts/config.php";
// Attempt select query execution
$sql = "SELECT * FROM offer_requests_test WHERE username = '" . ($_SESSION["username"]) . "'";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<th></th>";
echo "<th></th>";
echo "<th></th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<th class='hidden'>" . $row['uniqid'] . "</th>";
echo "<th>" . $row['car'] . "</th>";
echo "<th>" . $row['user'] . "</th>";
echo "<th>";
echo "<a href='read_request.php?uniqid=". $row['uniqid'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "</th>";
echo "<th>";
echo "<a href='update_request.php?uniqid=". $row['uniqid'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "</th>";
echo "<th>";
echo "<a href='delete_request.php?uniqid=". $row['uniqid'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</th>";
echo "</tr>";
}
// Free result set
mysqli_free_result($result);
} else{
echo "</br></br><p><b><i>Ingen informationer fundet.</i></b></p>";
}
} else{
echo "ERROR: Was not able to execute $sql. " . mysqli_error($link);
}
echo "</tbody>";
echo "</table>";
?>
<p>
<div href="" class="button alt small" onclick="hideCreate()">OPRET NYT TILBUD</div>
</p>
</div>
</div>
</div>
</div>
<!-- create -->
<div class="box">
<div class="inner">
<div class="content">
<div id="create">
<h4>1 - udfyld formularen</h4>
<form action="" method="post">
<div class="6u 12u$(xsmall) <?php echo (!empty($car_err)) ? 'has-error' : ''; ?>">
<label>Bil</label>
<input type="text" name="car" class="6u 12u$(xsmall)" value="<?php echo $car; ?>">
<span class="help-block"><?php echo $car_err;?></span>
</div>
<div class="6u 12u$(xsmall) <?php echo (!empty($user_err)) ? 'has-error' : ''; ?>">
<label>Bruger</label>
<input type="text" name="user" class="6u 12u$(xsmall)" value="<?php echo $user; ?>">
<span class="help-block"><?php echo $user_err;?></span>
</div>
<input type="hidden" name="company" value="<?php echo $company; ?>">
<input type="hidden" name="vat" value="<?php echo $vat; ?>">
<input type="hidden" name="username" value="<?php echo $username; ?>">
<input type="hidden" name="uniqid" value="<?php echo uniqid(); ?>" /></input>
</br></br>
</br></br><div class="table-wrapper">
<h4 class="pull-left">2 - vælg op til tre leasingselskaber</h4></br></br>
<table>
<tbody>
<tr>
<th class="hidden"><b>#</b></th>
<th><b>Vælg</b></th>
<?php
// Include config file
require_once "assets/scripts/config.php";
// Attempt select query execution
$sql = "SELECT l_comp FROM l_comp";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<th><b>Leasingselskab</b></th>";
echo "<th></th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<th>";
echo "<div class='6u 12u$(xsmall) <?php echo (!empty(" . $l_comp_err . ")) ? 'has-error' : ''; ?>
<input type='checkbox' id='" . $row['l_comp'] . "' name='l_comp' value='" . $row['l_comp'] . "'>
<label for='" . $row['l_comp'] . "'></label>
<span class='help-block'><?php echo " . $l_comp_err. ";?></span>
";
echo "</th>";
echo "<th>" . $row['l_comp'] . "</th>";
echo "</tr>";
}
// Free result set
mysqli_free_result($result);
} else{
echo "</br></br><p><b><i>Ingen informationer fundet.</i></b></p>";
}
} else{
echo "ERROR: Was not able to execute $sql. " . mysqli_error($link);
}
echo "</tbody>";
echo "</table>";
?>
</br></br>
<input type="submit" class="button alt small" value="OPRET TILBUDSKLADE">
FORTRYD
</form>
</div>
</div>
</div>
</div>
<!-- Footer -->
<footer id="footer" class="wrapper">
<div class="inner">
<div class="copyright">
© Fleets.dk - for virksomheder </br>
KONTAKT OS
</div>
</div>
</footer>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
<script src="assets/js/overlay_create.js"></script>
<script src="assets/js/overlay_login.js"></script>
</body>
I am creating my first php app and running into an issue on how I should try and edit a sql entry. I was planning on trying to get a modal window to pop up in order to edit.
When I select the edit link to open the modal window the variable says it is undefined. I am thinking it is because the Modal and variable are added to DOM before I click the link to edit and the variable never gets set. How do I get around this?
<?php
$sql = "SELECT id, image, name, score, points FROM teams";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)){
$teams_id = $row["id"];
$teams_image = $row["image"];
$teams_name = $row["name"];
$teams_score = $row["score"];
$teams_points = $row["points"];
// echo "id: " . $teams_id . " image path: " . $teams_image . " name: " . $teams_name . " score " . $teams_score . " points " . $teams_points . "</br>";
echo "<div class='row'>";
echo "<div class='row oval'>";
echo "<div class='col-4 flag {$teams_image}'>";
echo "</div>";
echo "<div class='col-8 text'>";
echo "<p>{$teams_name}</p>";
echo "</div>";
echo "</div>";
// edit and delete button
echo "<a href='add_teams_working.php?edit={$teams_id}' class='btn btn-outline-light btn-sm ml-4 align-self-center' data-toggle='modal' data-target='#editModal'>edit</a>";
echo "<button class='btn btn-outline-light btn-sm ml-1 align-self-center'>delete</button>";
echo "</div>";
}
}else {
echo "No teams added yet";
}
?>
<!-- SET VARIABLE for MODAL -->
<?php
if(isset($_GET['edit'])) {
$edit_id = $_GET['edit'];
$query = "SELECT * FROM teams WHERE id = $edit_id ";
$select_team = mysqli_query($conn, $query);
while($row = mysqli_fetch_assoc($select_team)) {
$edit_id = $row['id'];
$edit_image = $row['image'];
$edit_name = $row['name'];
}
}
?>
Here is modal if needed.
<div class="modal fade" id="editModal" tabindex="-1" aria-labelledby="editModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h3>Edit <?php echo $edit_name; ?> </h3>
</div>
<div class="modal-body">
<?php echo $edit_name; ?>
<?php echo $edit_image; ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button class="btn btn-primary" type="button">Save Changes</button>
</div>
</div>
</div>
</div>
When I click page number in DataTable, it is not moving to next page instead it loads the whole page again.
But if I click the DataTable sorting button and again I click the pagination page number, the DataTable is working fine. Can anyone help me to solve this. Thanks in advance.
<?php include 'header.php'; ?>
</style>
<!-- Breadcrumbs -->
<section class="bg-gray-7">
<div class="breadcrumbs-custom box-transform-wrap context-dark">
<div class="container">
<h3 class="breadcrumbs-custom-title">Sailing Schedules</h3>
<div class="breadcrumbs-custom-decor"></div>
</div>
<div class="box-transform" style="background-image: url(images/bg-typography.jpg);"></div>
</div>
<div class="container">
<ul class="breadcrumbs-custom-path">
<li>Home</li>
<li class="active">Sailing Schedule</li>
</ul>
</div>
</section>
<br>
<br>
<div class="container">
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Include config file
require 'config.php';
$sql = "SELECT * FROM long_sched";
if($result = mysqli_query($con, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table-custom table-custom-primary' id ='long_schd_table'>";
echo "<thead>";
echo "<tr>";
echo "<th>Service Name</th>";
echo "<th>Description</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td><a href=http://localhost/permatest/". $row['long_filepath'] . " target='_self' download>".$row['long_service']."</a></td>";
echo "<td>" . $row['long_desc'] . "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else {
echo "<p class='lead'><em>No records were found.</em></p>";
} else {
echo "ERROR: Could not able to execute ".$sql." " . mysqli_error($con);
}
// Close connection
mysqli_close($con);
?>
</div>
</section>
<br>
<br>
<?php include 'off_footer.php'; ?>
<script>
$('#long_schd_table').DataTable({});
</script>
The above code is giving this error but in my console I didn't get any error information.
This is the below code for displaying details of all available doctors in a template like format. You can also see a appointment button in the below code. I want to know how can i add a modal(bootstrap) for appointment button so i can add a datepicker script.
while($result = mysqli_fetch_assoc($results)){
echo '<div class="fetch">';
echo "<p>".$result['FIRST_NAME']." ".$result['LAST_NAME']."</p>";
echo "<p>".$result['QUALIFICATION']."</p>";
echo "<p>".$result['Specialization']."</p>";
echo "<p>".$result['Adress1']." ".$result['Adress2']."</p>";
echo "<p>"."<b>Consultation Fee-</b>"." ".$result['Consultation_Fee']."
</p>";
echo "<p>"."<b>Experience-</b>"." ".$result['Experience']."years"."</p>";
echo "<a href='appointment.php' class='btn btn-success'>Appointment</a>";
echo '</div>';
echo "<a href='appointment.php' class='btn btn-success' id='idTourDateDetails'>Appointment</a>";
$('#idTourDateDetails').datepicker({
dateFormat: 'dd-mm-yy',
minDate: '+5d',
changeMonth: true,
changeYear: true,
altField: "#idTourDateDetailsHidden",
altFormat: "yy-mm-dd"
});
You can refer it also: http://jsfiddle.net/sudiptabanerjee/93eTU/
<title>JustDental</title>
<link rel="stylesheet" href="css/justdental_style.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/bootstrap-min.css.css">
<link rel="stylesheet" type="text/css" href="css/custom.css">
<link rel="stylesheet" type="text/css" href="css/user_loginview.css">
<body style="background-color:#eee">
<div id = "container-userloginview">
<div id = "header-userloginview">
<?php
include("username_display.php");
?>
<!-- <h2>Just Dental</h2>-->
<ul id="nav-ul">
<li id="nav-li">
<a id="nav-a"><b><?php echo "Welcome", " ",$login_user;?></b></a>
<ul id="nav-ul" class="dropdown">
<li id="nav-li"><a id="nav-a" href="#">Edit Profile</a></li>
<li id="nav-li"><a id="nav-a" href="#">Change Username</a></li>
<li id="nav-li"><a id="nav-a" href="#">Change Password</a></li>
<li id="nav-li"><a id="nav-a" href="logout.php">Logout</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id = "content-userloginview">
<div id= "nav-userloginview">
<h5><strong>Locations</strong></h5>
<br><br><br>
<h5><strong>Appointment</strong></h5>
<br><br><br>
<h5><strong>Consultation Fee</strong></h5>
</div>
<div id = "main-userloginview">
<?php
include_once("connection.php");
$sql = "SELECT FIRST_NAME,QUALIFICATION,Specialization,LAST_NAME, Adress1, Consultation_Fee, Experience, Adress2 from t_doctorprofile";
$results = mysqli_query($db,$sql)
or die('Error in connection');
echo '<h3 style="color:purple"><strong>Available Dentists</strong></h3>';
while($result = mysqli_fetch_assoc($results)){
echo '<div class="fetch">';
//echo $result['FIRST_NAME']." ".$result['QUALIFICATION']." ".$result['Specialization'];
//echo "<td><img src='uploads/$row[1].png' height='100px' width='300px'></td>";
echo "<p>".$result['FIRST_NAME']." ".$result['LAST_NAME']."</p>";
echo "<p>".$result['QUALIFICATION']."</p>";
echo "<p>".$result['Specialization']."</p>";
echo "<p>".$result['Adress1']." ".$result['Adress2']."</p>";
echo "<p>"."<b>Consultation Fee-</b>"." ".$result['Consultation_Fee']."</p>";
echo "<p>"."<b>Experience-</b>"." ".$result['Experience']."years"."</p>";
echo "<a href='appointment.php' class='btn btn-success idTourDateDetails'>Appointment</a>";
echo "<button class='btn btn-primary btn-lg' data-toggle='modal' data-target='#myModal'>Appointment</button>";
echo "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
echo "<div class='modal-dialog'>";
echo "<div class='modal-content'>";
echo "<div class='modal-header'>";
echo "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>";
echo "<h4 class='modal-title' id='myModalLabel'>Modal title</h4>";
echo "</div>";
echo "<div class='modal-body'>";
echo "<div class='col-md-12'>";
echo "<div class='row'>";
echo "<label for='idTourDateDetails'>Tour Start Date:</label>";
echo "<div class='form-group'>";
echo "<div class='input-group'>';
echo'<input type='text' name='idTourDateDetails' id='idTourDateDetails' readonly='readonly' class='form-control clsDatePicker'> <span class='input-group-addon'><i id='calIconTourDateDetails' class='glyphicon glyphicon-th'></i></span>";
echo "</div>";
echo "</div>Alt Field:";
echo "<input type='text' name='idTourDateDetailsHidden' id='idTourDateDetailsHidden'>";
echo "</div>";
echo "</div>";
echo "<div class='modal-footer'>";
echo "<button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
}
?>
<div id = "footer-userloginview"></div>
<script>
$('.idTourDateDetails').datepicker({
dateFormat: 'dd-mm-yy',
minDate: '+5d',
changeMonth: true,
changeYear: true,
altField: "#idTourDateDetailsHidden",
altFormat: "yy-mm-dd"
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
I have searched a lot and am still having some trouble passing a Unique Id to a Value and then using that ID for a PHP MySQL Query to get the book info.
I currently am passing the unique ID to the Modal and Displaying it through an input type text. I am just having a hard time figuring out how to put the id into a php Variable
Here is my HTMl/PHP code
echo '<a data-toggle="modal" data-id="' . $book_id .'" title="Add this item" class="open-AddBookDialog btn btn-primary" href="#addBookDialog">View Info</a>';?>
<!-- Modal -->
<div class="modal hide" id="addBookDialog">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Book Info</h3>
</div>
<div class="modal-body">
<p>some content</p>
<?php
echo $test = '<input type="text" name="bookId" id="bookId"/>';
$book_info = get_book_info($book_id);
while($row1 = mysqli_fetch_array($book_info))
{
$email = $row['email'];
echo "<p><strong>Title: </strong>" . $row1['title'] . "</p>";
echo "<p><strong>Author: </strong>" . $row1['author'] . "</p>";
echo "<p><strong>Edition: </strong>" . $row1['edition'] . "</p>";
echo "<p><strong>ISBN: </strong>" . $row1['isbn'] . "</p>";
echo "<p><strong>Price: </strong>" . $row1['price'] . "</p>";
echo "<p><strong>Seller's Name: </strong>" . $row1['name'] . "</p>";
echo "<p><strong>Seller's E-mail: </strong><a href='mailto:$email'>$email</a></p>";
}?>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
here is my jquery
$(document).on("click", ".open-AddBookDialog", function () {
var myBookId = $(this).data('id');
$(".modal-body #bookId").val( myBookId );
});
You need to echo the value:
data-id="<?php $book_id ?>"
Use this instead:
data-id="<?php echo $book_id; ?>"
You could do something like this by javascript/coffee script.
($ "a[data-toggle=modal]").click ->
target = ($ #).attr('data-target')
url = ($ #).attr('href')
($ target).load(url)
URL = unique ID