gpt4 book ai didi

PHP:删除||确认删除

转载 作者:行者123 更新时间:2023-11-30 01:01:35 24 4
gpt4 key购买 nike

我遇到了问题。

我正在创建一个脚本,允许用户通过主 ID 选择记录,然后通过单击确认按钮删除该行。

这是具有以下形式的代码:“确认删除.php”

<?php
include("dbinfo.php");
$sel_record = $_POST[sel_record];

//SQL statement to select info where the ID is the same as what was just passed in
$sql = "SELECT * FROM contacts WHERE id = '$sel_record'";

//execute SELECT statement to get the result
$result = mysql_query($sql, $db) or die (mysql_error());//search dat db
if (!$result){// if a problem
echo 'something has gone wrong!';
}
else{
//loop through and get dem records
while($record = mysql_fetch_array($result)){
//assign values of fields to var names
$id = $record['ID'];
$email = $record['email'];
$first = $record['first'];
$last = $record['last'];
$status = $record['status'];
$image = $record['image'];

$filename = "images/$image";

}

$pageTitle = "Delete a Monkey";
include('header.php');

echo <<<HERE
Are you sure you want to delete this record?<br/>
It will be permanently removed:</br>
<img src="$filename" />
<ul>
<li>ID: $id</li>
<li>Name: $first $last</li>
<li>E-mail: $email</li>
<li>Status: $status</li>
</ul>
<p><br/>
<form method="post" action="reallydelete.php">
<input type="hidden" name="id" value="$id">
<input type="submit" name="reallydelete" value="really truly delete"/>
<input type="button" name="cancel" value="cancel" onClick="location.href='index.php'" /></a>
</p></form>
HERE;
}//close else
//when button is clicked takes user back to index
?>

这是它调用的reallydelete.php代码

<?php
include ("dbinfo.php");

$id = $_POST[id];//get value from confirmdelete.php and assign to ID
$sql = "SELECT * FROM contacts WHERE id = '$id'";//where primary key is equal to $id (or what was passed in)

$result=mysql_query($sql) or die (mysql_error());
//get values from DB and display from db before deleting it
while ($row=mysql_fetch_array($result)){
$id = $row["id"];
$email = $row["email"];
$first= $row["first"];
$last = $row["last"];
$status = $row["status"];

include ("header.php");
//displays here
echo "<p>$id, $first, $last, $email, $status has been deleted permanently</p>";
}

$sql="DELETE FROM contacts WHERE id = '$id'";
//actually deletes
$result = mysql_query($sql) or die (mysql_error());
?>

问题是它实际上永远不会进入“while”循环连接绝对没问题。

任何帮助将不胜感激。

最佳答案

1:不应该是$_POST[id];,而应该是$_POST['id'];更改此后尝试。如果它仍然不起作用,请尝试对结果执行 var_dump() 以查看它是否返回任何行。如果它是空的或没有行,那么它不工作是绝对正常的。并确保 id 正确到达您的 php 页面。

关于PHP:删除||确认删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20080248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com