0
我想編輯整個信息,這是通過模態框在JavaScript中顯示,但我能夠編輯列表中的第一個項目而不是other.Please告訴我如何編輯/更新下一個項目。下面是我的代碼PHP PDO數據庫
<?php
session_start();
$sessionArr = $_SESSION['user_session'];
include_once '../connection.php';
$userDetails = [];
try{
$userId = $sessionArr['userId'];
// Set the PDO error mode to exception
$sql = "SELECT * FROM details WHERE iUserId=:USERID ORDER BY id DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(':USERID'=>$userId));
$userDetails =$stmt->fetchAll(PDO::FETCH_ASSOC);
if($stmt->rowCount() < 0)
{
echo "no data found";
exit;
}
} catch(PDOException $error){
die("ERROR: Could not connect. " . $error->getMessage());
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>
<table>
<tr>
<th>Date</th>
<th>Name</th>
<th>Amount</th>
<th>Phone</th>
<th></th>
<th>Action</th>
</tr>
<?php foreach($userDetails as $item): ?>
<tr>
<td><?php print $item['date']; ?></td>
<td><?php print $item['p_name']; ?></td>
<td><?php print $item['amount']; ?></td>
<td><?php print $item['date']; ?></td>
<td></td>
<td><button id="myBtn">Edit</button></td>
<td>Delete</td>
</tr>
<?php endforeach; ?>
</table>
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<form action="" method="post">
<p id="emp">
<input type="text" name="e_name" id="e_name" placeholder="<?php echo
$item['e_name']; ?>" required style='text-transform:uppercase'>
</p>
<input type="submit" Value="Submit" name="submit" id="submit">
</form>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>
* 「我想編輯全信息」 * - 這調用'UPDATE'或'DELETE';不確定你想在這裏做什麼,以及相關的代碼在哪裏。 –
這不是問題的更新查詢它關於該模式框不打開第二項我有循環問題。 –
看看你的開發者控制檯然後看看是否有錯誤 –