[Hello!] I need help, I'm stuck at this point. I have index.php and m_update_pk.php that i include in index.php! In m_update_pk.php i have modal that opens when someone click on Edit in index table. I want to click on Edit and to open modal with another table in witch i can update my customers. You will see my code, i did everything i know and it isn't working, when i click on Edit nothing happens?? Thanks for helping, i am going crazy
index.php
case isset($_GET['poslovni_korisnici']): // Prikaz poslovnih korisnika
echo'
<h1>Poslovni korisnici</h1>
<a href="#insert_poslovni" class="btn btn-default btn-sm" data-toggle="modal" data-book-id="my_id_value">Unos</a>
</br>
</br>';
echo'
<table id="table_id" class="display">
<thead>
<tr>
<th>Partner name</th>
<th>Partner street</th>
<th>Partner zip</th>
<th>Partner city</th>
<th>Partner country</th>
<th></th>
<th><a href="edit.php?editPoslovni="><button type="button" class="btn btn-default btn-sm">Delete</button></a></th>
</tr>
</thead>
<tbody>';
$sql = "SELECT * FROM poslovni_partneri";
foreach ($dbh->query($sql) as $row)
{
echo'
<tr>
<td>'.$row['Partner_name'].'</td>
<td>'.$row['Partner_street'].'</td>
<td>'.$row['Partner_zip'].'</td>
<td>'.$row['Partner_city'].'</td>
<td>'.$row['Partner_country'].'</td>
<td><a href="#update_poslovni='.$row['Partner_id'].'" class="btn btn-default btn-sm" data-toggle="modal" data-book-id="'.$row['Partner_id'].'">Edit</a></td>
<td><input type="checkbox" id="blankCheckbox" value="option1" aria-label="..."></td>
</tr>';
}
echo'
</tbody>
</table>';
include 'includes/m_insert_pk.php'; // Insert poslovni korisnici
include 'includes/m_update_pk.php'; // Update poslovni korisnici
break;
m_update_pk.php
<?php
// ---- Pocetak modal-a za update poslovnih korisnika ---- //
echo'
<div class="modal fade bs-example-modal-lg" id="update_poslovni">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Uredi</span></button>
<h4 class="modal-title">Unos poslovnih korisnika</h4>
</div>
<div class="modal-body">';
if (isset($_POST['submit_upk'])) {
$partnername = $_POST['partner_name'];
$partnerstreet = $_POST['partner_street'];
$partnerzip = $_POST['partner_zip'];
$partnercity = $_POST['partner_city'];
$partnercountry = $_POST['partner_country'];
$sql = "UPDATE poslovni_partneri
SET
Partner_name = '$partnername',
Partner_street = '$partnerstreet',
Partner_zip = '$partnerzip',
Partner_city = '$partnercity',
Partner_country = '$partnercountry'
WHERE Partner_id = '$id'";
// Prepare statement
$stmt = $dbh->prepare($sql);
// execute the query
$stmt->execute();
}
echo'
<form method="POST" target="_parent" >
<table id="table_id" class="display">
<thead>
<tr>
<th>Partner name</th>
<th>Partner street</th>
<th>Partner zip</th>
<th>Partner city</th>
<th>Partner country</th>
</tr>
</thead>
<tbody>';
$id = $_GET['Partner_id'];
$sql = "SELECT * FROM poslovni_partneri WHERE Partner_id LIKE '$id'";
$stmt = $dbh->query($sql);
$row =$stmt->fetchObject();
$partner_name = $row['partner_name'];
$partner_street = $row['partner_street'];
$partner_zip = $row['partner_zip'];
$partner_city = $row['partner_city'];
$partner_country = $row['partner_country'];
echo'
<tr>
<td><input type="text" name="partner_name" value="'.$partner_name.'">'.$partnername.'</td>
<td><input type="text" name="partner_street" value="'.$partner_street.'">'.$partnerstreet.'</td>
<td><input type="text" name="partner_zip" value="'.$partner_zip.'">'.$partnerzip.'</td>
<td><input type="text" name="partner_city" value="'.$partner_city.'">'.$partnercity.'</td>
<td><input type="text" name="partner_country" value="'.$partner_country.'">'.$partnercountry.'</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<input type="submit" name="submit_upk" value="Uredi" />
</div>
</form>
</div>
</div>
</div>
<script>
//triggered when modal is about to be shown
$("#update_poslovni").on("show.bs.modal", function(e) {
//get data-id attribute of the clicked element
var bookId = $(e.relatedTarget).data("'.$id.'");
//populate the textbox
$(e.currentTarget).find("input[name="bookId"]"").val(bookId);
});
</script>';
// ---- Kraj modal-a za update poslovnih korisnika ---- //
?>
Try the following.
You will need jQueryUI library for this.
First of all, add a class name for the link, like:
<a class="update_poslovni" ....
Then, the JavaScript:
<script>
$(function(){
$("a.update_poslovni").click(function(e)
{
event.preventDefault(); // for the <a href="#" not to fire
var bookId = $(this).data("book-id");
$("#update_poslovni").find('input[name="bookId"]').val(bookId);
$("#update_poslovni").dialog({modal: true});
});
});
</script>
Use BootboxJS and prompt component. Check the example and use for you need.