|
|
|
สอบถามค่ะ จะทำปุ่ม Delete ให้ลบรายชื่อได้บนหน้าเพจ |
|
|
|
|
|
|
|
จะทำยังไงให้ปุ่ม Delete ใช้ได้คะ ตอนนี้กดยังไงก็ไม่ลบ รบกวนหน่อยค่ะ */\*
conn.php
Code (PHP)
<?php
$con= mysqli_connect("localhost","root"," ","name") or die("Error: " . mysqli_error($con));
mysqli_query($con, "SET NAMES 'utf8' ");
$sort_option = "ASC";
$query = "SELECT * FROM detail ORDER BY firstname $sort_option";
$query_run = mysqli_query($con, $query);
?>
delete.php
Code (PHP)
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "name";
$message2 = ". . ลบรายชื่อเรียบร้อย . .";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
$query = "SELECT * FROM detail";
$success = mysqli_query($conn,$query);
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query = "DELETE FROM `detail` WHERE id = '$id'";
$run = mysqli_query($conn,$query);
if ($success) {
echo "<script type='text/javascript'>alert('$message2');</script>";
echo "<script>";
echo "location=Showlist.php'";
echo "</script>";
}else{
echo "Error: ".mysqli_error($conn);
}
}
mysqli_close($conn);
?>
Showlist.php
Code (PHP)
<?php include "conn.php";
include "delete.php";
$i=1;
if(mysqli_num_rows($query_run) > 0)
{
foreach($query_run as $row)
{
?>
<tr class='data'>
<td><?= $i++ ?></td>
<td><?= $row['firstname']; ?></td>
<td><?= $row['lastname']; ?></td>
<td><?= $row['savedate']; ?></td>
<td><a href='delete.php?id="$result['id']."' id='btn'>Delete</a></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="3"> . . หาข้อมูลไม่พบ . .</td>
</tr>
<?php
}
Tag : PHP
|
ประวัติการแก้ไข 2022-06-20 09:15:19 2022-06-20 09:16:51 2022-06-20 10:18:19
|
|
|
|
|
Date :
2022-06-20 09:10:31 |
By :
Mirumu |
View :
930 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูครับ
Code (PHP)
<td><a href="delete.php?id=<?php echo $result['id']; ?>" id='btn'>Delete</a>
|
ประวัติการแก้ไข 2022-06-20 10:51:52
|
|
|
|
Date :
2022-06-20 10:51:26 |
By :
mongkon.k |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองแก้เองจนได้แล้วค่ะ ขอบคุณค่ะ */\*
|
|
|
|
|
Date :
2022-06-20 10:56:55 |
By :
Mirumu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|