I'm currently working on a project that envolves me using a admin dashboard. As apart of this i need to be able to display all users in the database and then edit them.
I want to be able to open the modal to edit the users, but whenever i open the modal its displaying the first entries data. How can i change this to display the different data for each line and then edit said data.
This is my current Code
<?php
include_once '../dashboard/dashHeader.php';
?>
<section>
<table class="table table-striped" style="border: 3px solid;">
<thead>
<tr>
<th>UID</th>
<th>Full Name</th>
<th>Email</th>
<th>User Name</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
include_once('../../includes/dbh.inc.php');
$sql = "SELECT * FROM users ORDER by usersId";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result)){
if ($row['type'] == 1) {
$role = "Admin";
} else {
$role = "User";
}
echo "<tr>";
echo "<td>".$row['usersId']."</td>";
echo "<td>".$row['usersName']."</td>";
echo "<td>".$row['usersEmail']."</td>";
echo "<td>".$row['usersUid']."</td>";
echo "<td>".$role."</td>";
echo '<td>
<button type="button" class="btn btn-link btn-sm btn-rounded" data-mdb-toggle="modal" data-mdb-target="#exampleModal">
Edit
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Editing: '.$row['usersUid'].'</h5>
</div>
<div class="modal-body">...</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-mdb-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</td>';
echo "</tr>";
}
?>
</tbody>
</table>
</section>
<?php
include_once '../dashboard/dashFooter.php';
?>
Without seeing what your JavaScript is doing, it's hard to debug
But first...
... you really need to fix the security of this page. This is vulnerable to HTML injection. You MUST escape all dynamic content (eg from your database), otherwise at best you will show mangled data, at worst you make it easy for a hacker to inject any code they like into your web page. At a minimum you should be running htmlspecialchars().
Ex echo "<td>".htmlspecialchars($row['usersName'])."</td>";
Related
Basically, the page is supposed to prompt the user (preferably with a modal) before confirming the action.I modified our web page so it would include modals on delete per individual row. The modal doesn't seem to open if I include id="modalname" on both the data-target button and on the modal id.
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Full Name</th>
<th>Company</th>
<th>Address</th>
<th>Email</th>
<th>Contact No.</th>
<th>Birth Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$con = mysqli_connect("localhost","root","","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query=mysqli_query($con,"select * from client order by lname")or die(mysqli_error());
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $row['lname'];?>,
<?php echo $row['fname'];?> <?php echo $row['mname'];?> </td>
<td><?php echo $row['company'];?></td>
<td><?php echo $row['address'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['contact'];?></td>
<td><?php echo $row['bday'];?></td>
<td>
<button type="button" data-toggle="modal" data-target="#deletemodale<?php echo $row['id'];?>" >Open Modal</button>
</td>
</tr>
</tbody>
</table>
Here's a sample code for my table. It includes the echoed values from the database with a button on each row for the modal.
Modal Code:
<div class="modal fade" id="deletemodale<?php echo $row['id'];?>" 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>
</div>
</div>
I tried this with tag and href earlier, the row id seems to be showing on the url if I hover on it but the modal won't open on both cases. The modal also seems to open properly if I remove the php tag on its id. I also only have this modal code for the rest of the rows because of its dynamic nature
From what i see you code is valid, but i dont see where your while loop is ending. If you dont have your modal code inside your while loop only one modal html code will be printed, so there will be a modal only for the last row['id'].Is that the case? Also your while loop should be ending before the tbody tag.
I took the liberty and added closing brace for your while loop just after the last </tr> (before the </tbody> in your first piece of code. I also copied the second piece of your code (you named it "Modal Code") right before that closing brace – since you give different id’s per modal, I assume that each row in your table has own modal. And everything works fine on my WAMP server.
Make sure that:
You have included jquery.js, bootstrap.css and bootstrap.js
You have enabled javascript in your browser.
i have created a button that will view the vehicles details when clicked. how ever, my data modal dialog does not show up. here is my codes..
<table class="table table-striped">
<tr>
<th width="40%">Plate Number</th>
<th width="30%">Type</th>
<th width="30%">View</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["plateNo_vehicle"]; ?></td>
<td><?php echo $row["vehicle_Type"];?></td>
<td><input type="button" name="view" value="view" id="<?php echo $row["id_vehicle"]; ?>" class="btn btn-info btn-xs view_data" /></td>
</tr>
<?php
}
?>
</table>
this is the modal class and the script. the script supposed to contain ajax that supposed to view all the vehicle detail but i changed it just to pop up a data modal dialog only because the data modal wont show up at all.
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Vehicles Details</h4>
</div>
<div class="modal-body" id="vehicle_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
script
<script>
$(document).ready(function(){
$('.view_data').click(function(){
$('#dataModal').modal("show");
});
});
It seems like you're loading jQuery twice.
First instance: <script src="../vendor/jquery/jquery.min.js"></script>
Second instance: <script src="ajax.googleapis.com/ajax/libs/jquery/2.2.0/…
this may be causing conflicts. Stick with the latest version only.
If you are using Bootstrap you can just add:
data-toggle="modal" data-target="#dataModal"
attributes in your button
I am displaying a table of values with two options, delete or update. When I select delete I want to display the row to be deleted. This last point using Bootstrap Modals.
This is my Delete Modal
<div class="modal bounceIn animated" id="Delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<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" id="myModalLabel">Delete a Campaign</h4>
</div>
<div class="modal-body edit-content">
<p>Please find the campaign ID to be deleted below</p>
<input type="text" name="bookId" id="bookId" value="" />
<table class='table table-bordered'>
<tr>
<th>#</th>
<th>Description</th>
<th>Creation Date</th>
<th>Credit</th>
<th>ROI</th>
<th>Active</th>
</tr>
<?php
$id = $row['data-campaignid'];// This is where I am having the problem
$stmt = $user_home->runQuery("SELECT * FROM campaigns WHERE id_campaigns=:id");
$stmt->execute(array(":id"=>$id));
while($row=$stmt->fetch(PDO::FETCH_BOTH))
{
?>
<tr>
<th>
<?php print($row['id_campaigns']); ?>
</th>
<th>
<?php print($row['descripcion']); ?>
</th>
<th>
<?php print($row['fec_creacion']); ?>
</th>
<th>
<?php print($row['saldo']); ?>
</th>
<th>
<?php print($row['ROI']); ?>
</th>
<th>
<?php print($row['active']); ?>
</th>
</tr>
<?php
}
?>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
<!-- modal-content -->
</div>
<!-- modal-dialog -->
</div>
<!-- end -->
So as you can see I am passing a value "bookid" to the modal using the following JQuery script
$(document).on("click", ".open-DeleteDialog", function () {
var myCampaignId = $(this).data('campaignid');
$(".modal-body #bookId").val( myCampaignId );
});
The difficulty I am encountering is how to use the value of the input (bookID) to pass it over to the PHP PDO Query and execute it while being able to show that data on the table.
JQuery is executed on client side while SQL queries are on server side.
So, you need to use AJAX. This would be a very long answer, please take a look at this CRUD+AJAX tutorial.
i want to pass mysql select value (UID) to css popup.this is my code what I have tried.but it's display empty textbox.this pop up button display when click on delete button.i want to pass relavent user UID to popup.
<table class="table table-striped table-bordered responsive">
<thead>
<tr>
<th>User ID</th>
<th>Facebook ID</th>
<th>Name</th>
<th>E-mail</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<?php
$query = 'SELECT * FROM Users ';
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo '<tr>';
echo '<td>'.$row['UID'].'</td>';
echo '<td class="center">'.$row['Fuid'].'</td>';
echo '<td class="center">'.$row['Ffname'].'</td>';
echo '<td class="center">'.$row['Femail'].'</td>';
echo '<td>'.'<a href="#" class="btn btn-info btn-setting" >'.'Delete'.'</a>'.'</td>';
echo '</tr>';
}
?>
</tr>
</tbody>
</table>
<form action="db_sql/db_delete_supplier.php" method="post" name="frm1" id="frm1" >
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Delete Supplier</h3>
</div>
<div class="modal-body">
<p>Are you sure to delete this supplier from system ...? </p>
</div>
<div class="modal-footer">
<input type="text" name="UID" value="<?php echo $row['UID'];?>" />
<!--Close
Delete-->
<input type="submit" class="btn btn-default" name="no" value="Close" />
<input type="submit" class="btn btn-primary" name="yes" value="Delete"/>
</div>
</div>
</div>
</div>
</form>
<?php echo "Edit"; ?>
Put this code in While loop , so this will open pop-up windows with query-string of cat-id.
Now from that ID you can fetch all records in pop-up.
This is possible solution you can do....
Note : you can pass any ID which is unique so that you can execute select query on pop-up page and it will fetch data from database
I need a help here.
I have an application - it queries some data from MySQL and present it in table (index.php file). Every row is a single customer record.
What I want to do is, when I click on the row, it opens customer record (customer.php file).
I tried the following code - when I click on the row, modal with remote page(customer.php only flashes, and then customer.php is loaded normally. I dont know why... does any body have an idea?
<table class="table table-hover container table-responsive">
<caption>Vyhledaní zákazníci</caption>
<thead>
<tr>
<th>Jméno</th>
<th>Příjmení</th>
<th>Email</th>
<th>Telefon</th>
<th>Adresa</th>
<th>Město</th>
<th>Akce</th>
</tr>
</thead>
<tbody>
<?php
while ($results = mysql_fetch_array($customers)) { ?>
<tr class="clickableRow active" href="customer.php?customerId=<?php echo $results['id'], '&search=', Input::get('search'); ?>" data-toggle="modal" data-target="#customerModal">
<td><?php echo $results['first_name']; ?> </td>
<td><?php echo $results['last_name']; ?> </td>
<td><?php echo $results['email']; ?> </td>
<td><?php echo $results['telephone']; ?> </td>
<td><?php echo $results['street']; ?> </td>
<td><?php echo $results['city']; ?> </td>
<td>Seznam zakázek
Nová zakázka
</tr>
<?php
} ?>
</tbody>
</table>
And modal:
<!-- Modal -->
<div class="modal fade" id="customerModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<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">Karta zákazníka</h4>
</div>
<div class="modal-body"><div class="te"></div></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->