Reputation: 105
This is Bootstrap popup (fade) form, and i have list of all members and the button next to them, and when you click, you can edit the profile of specified user (id). Everything works fine except <div class="modal fade" id="myModal6" role="dialog">
if i remove that, then i can edit each user, but with that, it only update first user.
$query = $handler->query('SELECT * FROM users');
<?php while($r = $query->fetch()) { ?>
<div class="modal fade" id="myModal6" role="dialog">
<div class="modal-dialog modal-sm">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Izmeni</h4>
</div>
<div class="modal-body">
<p>
<form action="admin.php?update_id=<?php echo $r['id']; ?>" method="post">
<div class="field">
<center><input type="text" name="updatename" class="form-control" required="" placeholder="<?php echo $r['id']; ?>"></center><br>
<center><input type="text" name="updatesurname" class="form-control" required="" placeholder="Prezime"></center><br>
<center><button name="submit" type="submit" class="btn btn-block btn-success"><span class="glyphicon glyphicon-ok"></span> Izmeni</button></center>
</div>
</form>
</p>
</div>
</div>
</div>
</div>
<?php } ?>
So, if i remove <div class="modal fade" id="myModal6" role="dialog">
it will work, but then my form will be screwd like this.
Upvotes: 1
Views: 70
Reputation: 4210
ID across the page needs to be unique if it needs to be executed correctly. Or esle it will be clubbed and it will produce unforced results.
List page:
<a type="button" data-toggle="modal" data-target="#myModal<?php echo $r['id']; ?>" class="btn btn-xs btn-info" href="#"><i class="glyphicon glyphicon-edit"></i></a>
This will create Seperate ID for all the Popups and you can use it.
Modified Code:
$query = $handler->query('SELECT * FROM users');
<?php while($r = $query->fetch()) { ?>
<div class="modal fade" id="myModal<?php echo $r['id']; ?>" role="dialog">
<div class="modal-dialog modal-sm">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Izmeni</h4>
</div>
<div class="modal-body">
<p>
<form action="admin.php?update_id=<?php echo $r['id']; ?>" method="post">
<div class="field">
<center><input type="text" name="updatename" class="form-control" required="" placeholder="<?php echo $r['id']; ?>"></center><br>
<center><input type="text" name="updatesurname" class="form-control" required="" placeholder="Prezime"></center><br>
<center><button name="submit" type="submit" class="btn btn-block btn-success"><span class="glyphicon glyphicon-ok"></span> Izmeni</button></center>
</div>
</form>
</p>
</div>
</div>
</div>
</div>
<?php } ?>
Upvotes: 1
Reputation: 7504
Instead of <div class="modal fade" id="myModal6" role="dialog">
use
<div class="modal fade" id="myModal<?php echo $r['id']; ?>" role="dialog">
Id of the element should be unique across the whole page.
Upvotes: 1