我需要通过URL栏将变量传递给我的其他页面。我有一个错误:注意:Undefined index: $id in C:\xampp\htdocs\Kyle_Site\Programming Rite\controle\delete.php on line 3
我认为我因未正确传递而收到此错误,但我不确定是否感谢任何帮助!
我在这里传递变量:
<a href="delete.php?id=<?php echo $username['id'] ; ?>">Delete</a></td>
这是应该传递的变量的位置:
<?php
require 'core.inc.php';
$id = $_GET['$id'];
if (isset($_POST['delete'])) {
$answer = $_POST['decision'];
if ($answer == 'yes') {
echo 'user deleted'; }
}
echo '<h1>Are you sure you want to delete '.$id.'?</h1>
<form name ="form1" method ="POST" action ="delete.php">
<input type="radio" name="decision" value="yes">Yes
<input type="radio" name="decision" value="no">No
<input type="submit" name="delete" value="Delete">
</form>';
?>
答案 0 :(得分:3)
替换
$id = $_GET['$id'];
通过
$id = $_GET['id'];
答案 1 :(得分:2)
你的获取变量是错误的。您还应该检查是否设置了get变量。
<?php
require 'core.inc.php';
if (isset($_GET['id'])
{
$id = $_GET['id']
if (isset($_POST['delete'])) {
$answer = $_POST['decision'];
if ($answer == 'yes') {
echo 'user deleted'; }
}
echo '<h1>Are you sure you want to delete '.$id.'?</h1>
<form name ="form1" method ="POST" action ="delete.php">
<input type="radio" name="decision" value="yes">Yes
<input type="radio" name="decision" value="no">No
<input type="submit" name="delete" value="Delete">
</form>';
}
答案 2 :(得分:1)
是$_GET['id']
。不需要$
。
答案 3 :(得分:0)
这不是'错误',而是'通知'。如果必须修复错误并不重要,则可以忽略通知。我的建议是检查你的$ id和isset()是否为null。如果其中一个为空,则会发生此通知。