通过带有PHP的url栏将变量传递给表单

时间:2012-12-11 07:57:07

标签: php forms

我需要通过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>'; 
?>

4 个答案:

答案 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。如果其中一个为空,则会发生此通知。