I want to update all data's inside in the while loop. But the problem is only one data is updating. For example:
Imagine that I have 3 data's in my tbl_rooms
columns: id, roomname, capacity
and the data will be fetch in the while loop, then all textboxes will be thrice cause of the while loop. Then I want to update all data's inside of the while loop. Please I need you guys. Thankyou!
Here's the code:
$db = mysqli_connect('localhost', 'root', '', 'psbr');
$query = mysqli_query($db, "SELECT * FROM rooms")
<script src = "http://code.jquery.com/jquery-1.9.1.js"></script>
<?php while ($row = mysqli_fetch_array($query)) { ?>
<input type="text" name="room_id" id="room_id" value="<?php echo $row['id']; ?>">
<?php } ?>
<input type="submit" name="submit" onclick="return chk()">
<script type="text/javascript">
function chk()
{
var roomid = document.getElementById('room_id').value;
var dataString = 'roomid='+ roomid;
$.ajax({
type: "post",
url: "sample_server.php",
data:dataString,
cache:false,
success: function(html){
alert("success!");
}
});
return false;
}
</script>
//sample_server.php
<?php
$db = mysqli_connect("localhost", "root", "", "psbr");
$roomid = $_POST['roomid'];
$update_status = "UPDATE rooms SET capacity = capacity - 1 WHERE id = '$roomid'";
mysqli_query($db, $update_status);
?>