javascript - Get dynamic data in radio button values and update MySQL database
Get the solution ↓↓↓I have a dashboard and I have one page and I have set three navigation tabs in one page with on click events where I can navigate through tab links in one page.
In Navigation tab I have users tab where I can access all users data. In user area I have change role button when I click on button the popup will appear and have radio buttons with two buttons (YES or NO). The only thing I want to achieve is to pass an user id to popup box, get dynamic values into radio button from database in popup box('already implement but it doesn't show values it shows only radio buttons') and change user roles without page refresh and stay on current tab.
Here is my code:
<tbody>
<?php
$query = mysqli_query($conn,"select * from tbl_users, tbl_user_roles WHERE tbl_users.user_role_id = tbl_user_roles.user_role_id");
$i = 1;
while($fetch = mysqli_fetch_array($query))
{?>
<tr>
<td><?php echo $i++?></td>
<td><?php echo $fetch['Username']?></td>
<td><?php echo $fetch['email']?></td>
<td><?php echo $fetch['role']?></td>
<td><a href="#" onclick="show_dialog()" id="btn-show-dialog">Change Role</a></td>
</tr>
<?php } ?>
</tbody>
popup box
<div class="overlay-roles" id="dialog-container">
<form method="POST">
<div class="popup-roles">
<?php
$roles_query = mysqli_query($conn,"select * from tbl_user_roles");
while ($roles = mysqli_fetch_array($roles_query)){
$user_role = $roles['user_role'];
echo "<tr><td><input type='radio' name='radio' value='<?php echo $user_role>' /></td></tr>";
}
?>
<div class="text-right">
<button class="conf-dialog-btn-no" id="ignore">Cancel</button>
<button name="delete-user" class="conf-dialog-btn-yes" id="confirm">Apply</button>
</div>
</div>
</form>
</div>
javascript to hande popup show/hide
<script type="text/javascript">
document.getElementById("btn-show-dialog").onclick = function(){show_dialog()};
var overlayme = document.getElementById("dialog-container");
function show_dialog() {
overlayme.style.display = "block";
}
document.getElementById("confirm").onclick = function(){confirm()};
function confirm() {/
overlayme.style.display = "none";
}
document.getElementById("cancel").onclick = function(){cancel()};
function cancel() {
overlayme.style.display = "none";
}
</script>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: foreach() argument must be of type array|object, null given
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.