我正在生成具有许多列的动态行。一栏有4个按钮,每个按钮具有不同的FORM操作。 我想使用ajax更新“行”详细信息。
此文件为dashboard.php
<?php
session_start();
include('database_connection.php');
$start = 0;
$size = 10;
$sql_display = "SELECT id, fullname, gender, verified FROM student LIMIT $start, $size";
$result = $db->query($sql_display);
?>
<html>
<body>
<table border='2px'>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Gender</th>
<th>Status</th>
<th>Issue</th>
<th>Remark</th>
</tr>
</thead>
<tbody>
<?php
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr><th scope='row'>". $idd=$row['id'] ; /*Displaying the ID to the dashboard*/
echo '</th><td>';
echo $row['fullname'];
echo "</td><td>";
if( $row['gender']=='1' )
echo "Female";
else
echo "Male";
echo "</td><td>";
/*The value i want to change from Not Issued to Issued when user clicks Issue button*/
if($row['verified']=="1" )
echo "Issued";
else
echo "Not Issued";
echo "</td><td>";
echo "<form method='POST'>
<!--===The id is used to select the entry uniquely from SQL Table===-->>
<input type='hidden' name = 'id' value = ".$idd .">
<input id='update' type = 'submit' class='bg-green' name= 'verify_it' value='Issue'><br/>
<input type = 'submit' class='bg-red' name= 'cancel_verify' value='Not Issue'><br/>
</form>
<form action='edit.php' method='POST'>
<input type='hidden' name = 'id' value = ".$idd .">
<input type = 'submit' class='bg-blue' name= 'edit' value ='Edit Record'>
</form>
";
?>
<form action='delete.php' method='POST' onsubmit="return confirm('Are you sure you want to submit?');" >
<?php
echo "<input type='hidden' name = 'id' value = ".$idd .">
<input type = 'submit' class='bg-red' name= 'delete' value ='Delete Record'>
</form> ";
echo "</td><td>";
echo "
<form id='Remarks' method='POST' action='update_remark.php'>
<input type='text' name='remark' placeholder='Enter Remarks' style='width:90%'/>
<input type='hidden' name = 'id' value = ".$idd."></input>
<input type='submit' class='bg-blue' name='update_remark' value='Remark' style='width:80%;'/>
</form>";
echo "</td></tr>";
}
}//end if
?>
<html>
<tr>
<th scope="row">-</th>
<td>-</td>
<td>---</td>
<td>---</td>
<td>---</td>
<td>---</td>
</tr>
</body>
</html>
这是更新文件:
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// database connection
include ('database_connection.php');
// checking which button clicked
if (isset($_POST['verify_it'])) {
$var_id = $_POST['id'];
$status_check = "SELECT verified, fullname, email FROM student WHERE id = '$var_id' LIMIT 1";
$s_check = $db->query($status_check);
$s_value = $row = $s_check->fetch_assoc();
if ($s_value['verified'] == "0") {
$sql_update_status = "UPDATE student SET verified = 1 WHERE id='$var_id' ";
$db->query($sql_update_status);
$_SESSION['fullnameemail'] = $s_value['fullname'];
$_SESSION['emailid'] = $s_value['email'];
//include ('PHPMailer/sendmail.php');
if ($_SESSION['dashboard'] == "true") {
header("Location: dashboard.php");
}
else {
header("Location: admin.php");
}
}
else {
echo "<script>alert('Already Issued')</script>";
}
}
elseif (isset($_POST['cancel_verify'])) {
$var_id = $_POST['id'];
$status_check = "SELECT verified FROM student WHERE id = '$var_id' LIMIT 1";
$s_check = $db->query($status_check);
$s_value = $row = $s_check->fetch_assoc();
if ($s_value['verified'] == "1") {
$sql_update_status = "UPDATE student SET verified = 0 WHERE id='$var_id' ";
$db->query($sql_update_status);
}
if ($_SESSION['dashboard'] == "true") {
header("Location: dashboard.php");
}
else {
header("Location: admin.php");
}
}
} // requested Method call
else {
header("Location:login.html");
}
?>
由于我是Ajax的新手,所以我很困惑在哪里插入javascript和ajax。我想要的是将表行中的文本从“未发行”更改为“已发行”,或在删除时淡出。 我试图遵循一些教程,但是它们非常令人困惑
我还想要一个按钮,它将ajax显示的所有记录从“未发行”更新为“发行”状态。