wanted to make my users able to delete an mysql row
I changed the =
to =>
. Unfortunately I get another error message:
Warning: Invalid argument supplied for foreach() in /home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html on line 31
I am getting a php error message. What am i doing wrong?
Parse error: syntax error, unexpected '=', expecting ')' in /home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html on line 31
My html looks like this:
<html>
<head>
<title>Retrieve data from database </title>
</head>
<body>
<?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['.$row['id'].']" type="checkbox">';
echo $row['topic']. " " .$row['name']. " " .$row['datetime'] . "<br />";
}
$delete = $_POST['delete'];
foreach($delete as $id = $value)
{
$id = mysql_real_escape_string($id);
mysql_query("DELETE FROM table_name WHERE id = $id");
}
// Close the database connection
mysql_close();
?>
</body>
</html>
Your issue lies in the foreach loop, where you have $id = $value
. I suspect you mean:
foreach($delete as $id => $value)
{
$id = mysql_real_escape_string($id);
mysql_query("DELETE FROM table_name WHERE id = $id");
}
Note the changing of =
to =>
.
For more about the => operator, view the related post here.
链接地址: http://www.djcxy.com/p/58186.html上一篇: 如何删除字符串末尾的所有特定字符?
下一篇: 想让我的用户能够删除一个mysql行