用这个替换你的 php 部分:
<?php
require('connection.php');
$status = '';
$text = '';
$com = '';
$url = 'index.php';
function timer($url){
sleep(3);
header('Location: ' . $url);
}
if(isset($_POST['addCom'])) {
$com= mysqli_real_escape_string($db,$_REQUEST['com']);
$text = mysqli_real_escape_string($db,$_REQUEST['text']);
$stmt = $db->prepare("insert into testcomments (com,text) values (?,?)");
$stmt->bind_param('ss',$com,$text);
$stmt->execute();
$status = "Done ";
$com= '';
timer($url);
}
?>