我有一个表单,它从MySQL表中获取输入以显示值,并使用某些操作项更新它。
现在,我正在尝试使用“更新”功能,这样我就可以将表单上的“注释”和“状态”字段更新为最新更改。但是,我的代码有问题。首先,它似乎没有调用“ajax_updateBugStats.php”文件。
结果是它没有在MySQL表中更新。 这是表格:
<form id = "bugStats">
<tr>
<th>
ID
</th>
<th>
ISSUE
</th>
<th>
REFERER
</th>
<th>
URI
</th>
<th>
STATUS
</th>
<th>
COMMENTS
</th>
<th>
EMAIL
</th>
<!-- <th>
USER
</th> -->
<th>
TIME
</th>
<th>
<select id = "dropdown_action" name = "dropdown_action">
<option id = "sub" type= "submit" name= "sub" value="UPDATE">UPDATE</input>
<option id = "sub" type= "submit" name= "sub" value="EMAIL">EMAIL</input>
</select>
<input id = "sub" type= "submit" name= "sub" value="SUBMIT"/>
</th>
</tr>
</form>';
$sqlstring2 = "SELECT id, description, httpreferer, requesturi, status, comments, email, wpuserid, requesttime FROM isnew.bugtracker ORDER BY id DESC LIMIT 50";
$result2 = mysqli_query($con, $sqlstring2);
while ($row2 = mysqli_fetch_assoc($result2)) {
$id = $row2['id'];
$description = $row2['description'];
$httpreferer = $row2['httpreferer'];
$requesturi = $row2['requesturi'];
$status = $row2['status'];
$comments = $row2['comments'];
$email = $row2['email'];
$requesttime = $row2['requesttime'];
echo '
<tr>
<td>
<input form = "bugStats" id = "bugID" type = "hidden" name = "bugID['.$id.']" value = "'.$id.'">
<strong>'.$id.'</strong>
</td>
<td>
'.$description.'
</td>
<td>
'.$httpreferer.'
</td>
<td>
'.$requesturi.'
</td>
<!-- <td>
'.$httpuseragent.'
</td>
<td>
'.$remoteaddress.'
</td> -->
<td>
<select form = "bugStats" id = "status" name = "status['.$id.']">
<option id = "blankStat" value= "" '.(($status == '')?'selected = "selected"':"").'> </option>;
<option id = "openStat" value= "Opened" '.(($status == 'Opened')?'selected = "selected"':"").'> Opened </option>;
<option id = "investigateStat" value= "Ticket - Investigated" '.(($status == 'Ticket - Investigated')?'selected = "selected"':"").'> Ticket - Investigated </option>;
<option id = "inProgressStat" value= "Ticket - In Progress" '.(($status == 'Ticket - In Progress')?'selected = "selected"':"").'> Ticket - In Progress </option>;
<option id = "closedStat" value= "Closed" '.(($status == 'Closed')?'selected = "selected"':"").'> Closed </option>;
</select>
</td>
<td>
<textarea form = "bugStats" id = "comments" name = "comments['.$id.']" rows = "4" cols = "50">'.$comments.'</textarea>
</td>
<td>
'.$email.'
</td>
<!-- <td>
'.$wpuserid.'
</td> -->
<td>
'.$requesttime.'
</td>
<td>
<!-- <input id = "sub" type= "submit" name= "sub" value="UPDATE"/> -->
<input form = "bugStats" type="checkbox" name="action_checkbox['.$id.']" value="'.$id.'"><br>
</td>
</tr>';
}
这是处理它的ajax调用:
<script>
$("#bugStats").submit(function(event)
{
var checked = $("#bugStats").serializeArray();
alert("success");
$.ajax({
type: 'POST',
url: '/ajax_updateBugStats.php',
data: { checked: checked },
success: function(server_response)
{
if(server_response == "1")
alert("yes");
else if (server_response == "0")
alert("no");
else
alert("gro");
}
// error: AjaxFailed
});
});
alert("nice");
</script>
这是ajax调用使用的php文件(ajax_updateBugStats.php):
<?php
require_once 'wp-config.php';
require_once 'dbinclude.php';
$comments = array();
$status = array();
if (isset($_POST))
{
foreach($_POST['action_checkbox'] as $key => $value)
{
$id[] = $_POST['bugID'][$key];
$status[] = $_POST['status'][$key];
$comments[] = $_POST['comments'][$key];
}
}
$count = count($_POST['action_checkbox']);
for ($x = 0; $x < $count; $x++)
{
$sqlstringWPUsers = "UPDATE bugtracker SET status = '{$status[$x]}', comments = '{$comments[$x]}' WHERE id = '{$id[$x]}'";
$resultWPUsers = mysqli_query($mysqlconn, $sqlstringWPUsers);
}
mysqli_close($con);
?>