【问题标题】:wanted to make my users able to delete an mysql row想让我的用户能够删除 mysql 行
【发布时间】:2014-10-25 15:33:39
【问题描述】:

我将= 更改为=>。不幸的是,我收到另一条错误消息:

警告:在第 31 行的 /home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html 中为 foreach() 提供的参数无效


我收到一条 php 错误消息。我做错了什么?

解析错误:第 31 行 /home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html 中出现语法错误、意外 '='、期望 ')'

我的 html 看起来像这样:

<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>

【问题讨论】:

标签: mysql checkbox delete-row


【解决方案1】:

您的问题在于 foreach 循环,您有 $id = $value。我怀疑你的意思是:

foreach($delete as $id => $value)
{
    $id = mysql_real_escape_string($id);
    mysql_query("DELETE FROM table_name WHERE id = $id");
}

注意将= 更改为=&gt;

有关 => 运算符的更多信息,请查看相关帖子here

【讨论】:

  • 非常感谢我更改了它,但现在我收到了另一个错误消息。警告:在第 31 行的 /home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html 中为 foreach() 提供的参数无效跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-17
  • 1970-01-01
  • 1970-01-01
  • 2019-12-06
  • 1970-01-01
  • 2021-07-18
相关资源
最近更新 更多