求~删除前确认框 php

来源:百度知道 编辑:UC知道 时间:2024/07/04 16:37:10
我做的一个网站信息删除页
delete.php 给出超连接到delete2.php进行删除。
想让用户在点击超连接之后,先弹出个确认框 是否确定删除
下面是我没有加确认框的代码,请各位帮我改一下~ 谢谢了。
delete.php:
<h1>Select Desired Phone Record To Delete</h1>

<?php

include 'database_conn.php';

$sql = "SELECT phoneid, model, brand FROM product";

$queryresult = mysql_query($sql) or die (mysql_error());

while($row = mysql_fetch_array($queryresult)){
$phoneid = $row['phoneid'];
$model = $row['model'];
$brand = $row['brand'];
echo "<a href = \"delete2.php?phoneid=$phoneid\">$model</a> $brand <br /> \n";
}

mysql_free_result($queryresult);
mysql_close($conn);
?>

delete2.php:
<?
$phoneid = $_GET['phoneid']; // need this to identify the particular record to delete

echo "<h1>Deleting

echo "<a href = \"delete2.php?phoneid=$phoneid\">$model</a> $brand <br /> \n";
把这行改改就行了。
echo "<a href = \"delete2.php?phoneid=$phoneid\" onclick=\"if(confirm('确实要删除此条记录吗?')) return true;else return false; \" >$model</a> $brand <br /> \n";

你的代码写得很简单,所以就用这个简单的方式了。链接上加了个onclick 事件。

修改delete2.php
<script language=javascript>
if(!confirm('确实要删除此条记录吗?'))
{
window.location.href='delete.php';
}
</script>
<?
$phoneid = $_GET['phoneid']; // need this to identify the particular record to delete

echo "<h1>Deleting record ... </h1>";

include 'database_conn.php'; // make db connection

$sql = "DELETE FROM product WHERE phoneid = $phoneid";

mysql_query($sql) or die (mysql_er