0
我真的可以使用一些幫助。我對所有人都有點新鮮感。我試圖做一個工具從我的數據庫的表中刪除行。這是我到目前爲止,它可以顯示錶格中的行與一個複選框鏈接到該行和刪除按鈕來刪除選定的行。但是當我點擊刪除時,我收到以下錯誤消息。如何從mysql數據庫刪除行使用php刪除表單按鈕
警告:mysql_real_escape_string()預計參數1是串,陣列中的給定/home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html上線31
此之下的代碼:
<html>
<head>
<title>Retrieve and delete data from database </title>
</head>
<body>
<form action="" method="post">
<?php
// Connect to database server
mysql_connect("mysql7.000webhost.com", "a9083956_test", "sesam") or die (mysql_error());
// Select database
mysql_select_db("a9083956_test") or die(mysql_error());
// SQL query
$strSQL = "SELECT * FROM forum_question";
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {
// Write the value of the column FirstName (which is now in the array $row)
echo '<input name="delete[]" type="checkbox">';
echo $row['topic']. " " .$row['name']. " " .$row['datetime'] . "<br />";
}
$delete = mysql_real_escape_string($_POST['delete']);
for($i=0; $i < count($delete); $i++){
mysql_query("DELETE FROM table_name WHERE id = $delete[$i] ");
}
// Close the database connection
mysql_close();
?>
<input type="submit" value="Delete selected items">
</form>
</body>
</html>