gpt4 book ai didi

php - undefined variable : del on line 18

转载 作者:行者123 更新时间:2023-11-29 11:33:53 24 4
gpt4 key购买 nike

尝试编写从 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com