試圖在這裏執行一個非常簡單的任務。
我有一個<ol>
包含4行數據在一些方便<li>
s。我想添加一個刪除按鈕來從表格中刪除該行。 delete.php中的腳本似乎已經完成,但是當我返回並檢查dashboard.php和PHPMyAdmin以獲取列表時,該行從未被刪除。
下面是刪除按鈕的代碼(PHP內):
Print "<form action=delete.php method=POST><input name=".$info['ID']." type=hidden><input type=submit name=submit value=Remove></form>";
移動到delete.php:
<?
//initilize PHP
if($_POST['submit']) //If submit is hit
{
//then connect as user
//change user and password to your mySQL name and password
mysql_connect("mysql.***.com","***","***") or die(mysql_error());
//select which database you want to edit
mysql_select_db("shpdb") or die(mysql_error());
//convert all the posts to variables:
$id = $_POST['ID'];
$result=mysql_query("DELETE FROM savannah WHERE ID='$id'") or die(mysql_error());
//confirm
echo "Patient removed. <a href=dashboard.php>Return to Dashboard</a>";
}
?>
數據庫是:shpdb 表是:大草原
想法?
你能打印即回聲 「DELETE FROM WHERE大草原ID = '$ ID'」;看看$ id是否真的被替換的值。 – jatanp 2009-10-14 23:55:26
此代碼易受SQL注入攻擊。 http://php.net/manual/en/security.database.sql-injection.php – 2009-10-14 23:58:24
此外,你必須確保人們不能通過猜測id's來刪除任意的東西。如果這是用戶相關的數據,什麼阻止我猜測ID和刪除其他人的信息。 – BeWarned 2009-10-15 00:47:38