php - undefined variable : del on line 18

标签 php mysql

尝试编写从 MySQL 数据库中删除一行的代码。出现错误 undefined variable :第 18 行 C:\wamp64\www\allstuff\del_data.php 中的 del,但我已经初始化了 $del var。我认为,由于该错误,我的删除功能不起作用。 这是代码:

error_reporting(E_ALL & ~E_DEPRECATED);

$hostname = "localhost";
$username = "root";
$password = "";

$dbName = "lage_base";
$table = "lage_table";

$conn = mysql_connect($hostname, $username, $password);

mysql_connect($hostname, $username, $password) or die ("No Connection");

mysql_select_db($dbName) or die (mysql_error());

$del = $query = "DELETE FROM $table WHERE id='$del'";
//mysql_select_db('lage_base');
mysql_query($query) or die(mysql_error());

$query = "SELECT * FROM lage_table";
$res = mysql_query($query) or die(mysql_error());
$row = mysql_num_rows($res);
//$retval = mysql_query($query,$conn);

echo ('
    <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
        <html xmlns=\"http://www.w3.org/1999/xhtml\">

        <head>

            <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1251\" />

            <link rel="stylesheet" href="style.css" type="text/css">

        </head>
    <body id="viewData">
        <table>
            <tr>
            <td id="nummer"><b>#</b></td>
            <td align = \"center\" id="date"><b class="tabtext">Datum</b></td>
            <td align = \"center\" id="name1"><b class="tabtext">Name</b></td>
            <td align = \"center\" id="stuck"><b class="tabtext">Stuck</b></td>
            </tr>
    ');

while ($row = mysql_fetch_array($res)) {
echo "<tr>\n";
echo "<td class='rowCont'>".$row['id']."</td>\n";
echo "<td class='rowCont'>".$row['data']."</td>\n";
echo "<td class='name2'>".$row['name']."</td>\n";
echo "<td class='rowCont'>".$row['stuck']."</td>\n</tr>\n";
echo "<td><a name=\"del\" href=\"del_data.php?del=".$row["id"]."\">Loschen</a></td>\n";
echo "</tr>\n";
}

echo ("</table>\n");

mysql_close();

echo ("<div style=\"text-align: center; margin-top: 10px;\"><a href=\"index.html\">Zuruck!</a></div>");


?>

我将不胜感激每一个答案! 附言。对于我的低技能和愚蠢的问题感到抱歉(=。

最佳答案

尝试这样:

$del = $_GET['del'];
$query = "DELETE FROM $table WHERE id='$del'";

关于php - undefined variable : del on line 18,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36942191/

相关文章:

c# - 使用C#连接MySQL数据库

javascript - 如何使用 JS 添加和删除 CSS 类

mysql - 从两个表中获取一定时间段内SUM数量的数据

java - 什么类允许我操纵索引和值?

php - 阻止谷歌索引成员(已将其个人资料设置为私有(private))个人资料

mysql - 连接Elasticsearch并删除mysql服务器

MySQL性能;大数据表还是多数据表?

php - 从MySQL基于两列选择多个行值

php - 将更改写回 Zend Dom 查询对象

php - 遇到 Ubuntu LAMP 堆栈问题