ID로 검색 할 때 prepare 준비를하기 전에 준비가 완료되었지만 prepared statement 결과를 추가 한 후 ID가 존재하지 않습니다!prepared statement 결과에 broken code가 추가되었습니다.
이 내 코드입니다 : 아직 문을 준비 전혀 없기 때문에,
<form action="" method="post">
<div class="col-lg-3">
<label for=""><h4>Search by ID</h4></label>
<div class="input-group">
<input name="search" type="number" class="form-control">
<span class="input-group-btn">
<button name="submit" class="btn btn-default" type="submit">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
<hr>
</div>
<div class="col-lg-12">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Ime</th>
<th>Prezime</th>
</tr>
</thead>
<tbody>
</tbody>
<?php
if(isset($_POST['search'])) {
$search_id = $_POST['search'];
mysqli_set_charset($connection, "utf8");
$stmt = mysqli_prepare($connection, "SELECT id, ime, prezime FROM anketa WHERE id = ? LIMIT 1");
if(isset($stmt)) {
mysqli_stmt_bind_param($stmt, 'i', $search_id);
mysqli_stmt_bind_result($stmt, $ank_id, $ank_ime, $ank_prezime);
mysqli_stmt_execute($stmt);
}
if(!$stmt) {
die("QueryFailed" . mysqli_error($connection));
}
if(mysqli_stmt_num_rows($stmt) > 0) {
while(mysqli_stmt_fetch($stmt)):
echo "<tr>";
echo "<td>{$ank_id}</td>";
echo "<td>{$ank_ime}</td>";
echo "<td>{$ank_prezime}</td>";
echo "<td><a class='btn btn-info btn-xs' href='search.php?source=edit&edit={$ank_id}'><i class='fa fa-pencil-square-o'></i> Edit</a></td>";
echo "<td><a class='btn btn-danger btn-xs' onClick=\"javascript: return confirm('Delete?'); \" href='search.php?delete={$ank_id}'><i class='fa fa-trash-o'></i> Delete</a></td>";
endwhile;
} else {
echo "ID doesn't exist!";
}
}
?>
</table>
</div>
</div>
<?php
if(isset($_GET['delete'])) {
$ank_id = $_GET['delete'];
if(isset($_SESSION['user_role'])) {
if($_SESSION['user_role'] == 'admin' || 'user_role'] == 'superadmin') {
$the_anketa_id = mysqli_real_escape_string($connection, $_GET['delete']);
$query = "DELETE FROM anketa WHERE id = {$ank_id} ";
$delete_anketa = mysqli_query($connection, $query);
header("Location: search.php");
}
}
}
?>
</form>
</div>
<?php
if(isset($_GET['source'])) {
$source = $_GET['source'];
if($source = 'edit') {
include "includes/edit.php";
} elseif($source = 'submit') {
header("Location: search.php");
}
}
?>
<?php
} else {
echo "<script>alert('No access!')</script>";
}
?>
나는 문제가 삭제를 위해 문 또는 코드를 준비하는 경우 몰라?
[최소의 완전하고 검증 가능한 예제를 만드는 방법] (https://stackoverflow.com/help/mcve)을 읽어보십시오. 거기에 많은 코드가 필요하지 않습니다. – Pharaoh
죄송합니다, 장래에 그렇게하겠습니다. – shone83
질문을 편집하고 해당 HTML 항목 (중요하지 않은 항목)을 모두 제거하면이 질문에 대해 더 빠르고 나은 답변을 얻을 수 있습니다. – Pharaoh