Click here to Skip to main content
15,662,893 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have HTML form with a button, when I click button the modal form will popup but when I put php code inside the href it will not popup. Please help me. Thank you in advance.

What I have tried:

This code show the modal popup:
<td><a href="#myModal" data-toggle="modal"><button class="btn btn-primary">Edit Record</button></a></td>

This one is not show the modal popup:
<td><a href="#myModal <?php echo '?id='.$id; ?>" data-toggle="modal"><button class="btn btn-primary">Edit Record</button></a></td>
Updated 25-Sep-18 14:27pm

Based on what you have posted, I think you might need to update the code to use data attribute to pass the id into the modal. Then read the value using JavaScript. Something like below.

<td><a href="#myModal" data-id="<?php echo $id; ?>" data-toggle="modal"><button class="btn btn-primary">Edit Record</button></a></td>

here is an example: bootstrap modal popup with data - JSFiddle[^]

JavaScript · Bootstrap[^]
Share this answer
Kenjiro Aikawa 25-Sep-18 20:19pm    
Hi Bryan, Thank you for the solution I have fix my problem about passing data from modal and showing the modal by separating the it to my user account page but the problem is when I include that modal page to my query my table was ruin. i don't know what's the problem. I will post my code.
<div class="container">
            <table class="table table-bordered" style="position: fixed; margin-left:12px; margin-top:210px; margin-bottom:10px; width:87%">
                        <th style="padding-bottom:15px;">No.</th>
                        <th style="padding-bottom:15px;">ID Number</th>
                        <th style="padding-bottom:15px;">Name</th>
                        <th style="padding-bottom:15px;">Department</th>
                        <th style="padding-bottom:15px;">Position</th>
						<th style="padding-bottom:15px;">Role</th>
						<th style="padding-bottom:15px;">Status</th>
                        <th style="padding-bottom:15px;">Option</th>
                <tbody class="table-users">

					  $sql = "SELECT id, userid, name, department, position, status, role FROM tbl_user WHERE role<>'SUPER ADMIN'";
					  foreach ($db->query($sql) as $row) {	            			
						<td><?php echo $row['id']; ?></td>
						<td><?php echo $row['userid']; ?></td>
						<td><?php echo $row['name']; ?></td>
						<td><?php echo $row['department']; ?></td>
						<td><?php echo $row['position']; ?></td>
						<td><?php echo $row['role']; ?></td>
						<td><?php echo $row['status']; ?></td>
      <a href="#edit_<?php echo $row['id']; >" class="btn btn-success btn-sm" 
      data-toggle="modal"><span class="glyphicon glyphicon-edit"></span> Edit</a>
      <?php include('edit_delete_modal.php'); ?>
					<?php } ?>
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900