私は従業員管理システムを作成しようとしていますが、今ではいくつかのデータベースコンテンツを使用してテーブルを作成しています。
これで、すべての行の最後にあるボタンをクリックすると、選択した行が削除されます。 これを行うには、delete.phpという名前のファイルを呼び出すJquery $ .getメソッドを使用しようとしています。このメソッドはジョブを実行し、htmlから行をアニメーション化して削除します。
問題は、アニメーションが始まりますが、phpファイルはデータベースからレコードを削除しないことです。私も、エラーのためにconsole.logしようとしましたが、あなたは下のスクリーンショットで見ることができるように、それはちょうどここ
は、コードの...私の代わりに、エラーコードのページのHTMLコードを提供します私は、テーブルを生成するために使用:$(".delete").click(function(){
var del_id = $(this).attr("id");
var tr = $(this).parent().parent();
console.log(del_id);
console.log(tr);
$.get("php/delete.php", { id: del_id } , function(error){
//console.log(error);
tr.fadeOut("1s",function(){
$(this).remove();
});
});
});
と私のdelete.phpコードがあります:
ここ<?php
$sql = "SELECT * FROM dipendente";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table class='table table-striped table-hover'>".
"<thead>".
"<tr>".
"<td>id</td>".
"<td>nome</td>".
"<td>cognome</td>".
"<td>impiego</td>".
"<td>permessi</td>".
"<td>contratto</td>".
"<td>inizio</td>".
"<td>fine</td>".
"<td>edit</td>".
"</tr>".
"</thead>";
echo "<tbody>";
// output data of each row
while($row = $result->fetch_assoc()) {
$id = $row["id"];
echo "<tr id=".$row["id"].">".
"<td>" . "#". $row["id"]. "</td>" .
"<td contenteditable='false'>" . $row["nome"]. "</td>".
"<td contenteditable='false'>" . $row["cognome"] . "</td>".
"<td contenteditable='false'>" . $row["impiego"] . "</td>".
"<td contenteditable='false'>" . $row["permessi"] . "</td>".
"<td contenteditable='false'>" . $row["contratto"] . "</td>".
"<td contenteditable='false'>" . $row["inizio"] . "</td>".
"<td contenteditable='false'>" . $row["fine"] . "</td>".
"<td>" .
"<span class='glyphicon glyphicon-pencil' aria-hidden='true'></span>" .
" " .
"<span class='glyphicon glyphicon-remove-sign' aria-hidden='true'></span>" .
"<a href='#' id='$id' class='delete'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></a>".
" ".
"<span class='glyphicon glyphicon-ok-sign' aria-hidden='true'></span>".
"</td>".
"</tr>";
}
echo "</tbody>";
echo "</table>";
} else {
echo "0 results";
}
は私のjqueryのコードです
<?php
$id = $_GET['del_id'];
$dbc = mysqli_connect('localhost', 'root', 'root', 'gestione_personale') or die('Connection error!');
$query = "DELETE FROM dipendente WHERE id = '$id'";
mysqli_query($dbc, $query) or die('Database error!');
header('location:../index.php');
何か間違っていますか?
'$ id'をPHPに転送するかどうかを試してみましたか? – Sand
これは最後の行 'header( 'location:../ index.php');'によると思います。コンソールのエラーを確認してください。 – siva
あなたは '$ id = $ _GET ['id'];' $ id = $ _GET ['del_id']; ' – siva