尝试编写将从MySQL数据库中删除一行的代码。得到错误 未定义的变量:第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>");
?>
我很感激每一个答案! PS。我的低技能和愚蠢的问题(=。
答案 0 :(得分:1)
试试这样:
$del = $_GET['del'];
$query = "DELETE FROM $table WHERE id='$del'";