1帮助,检索GET变量时未定义的索引

时间:2013-12-25 21:15:38

标签: php get

我正在尝试检索$ _GET变量,但它一直告诉我,我有一个未定义的索引,就好像该变量没有被存储一样。

<html>
<body>
    <form action="commentEdit.php" method="post">
        <label for="content">Content:</label>           
        <input type="text" id="content" name="content" /> <br />
        <input type="submit" value="Submit" name="submit"/>
        <input type="reset" value="reset" name="reset"/>
    </form>
<?php

    if(isset($_POST['submit']))
    {
        $connection = mysqli_connect("localhost", "root", "","forum_db");
            if(mysqli_connect_errno())
        {
            echo "Error: Could not connect to database.Please try again later";
            exit;
        }           

        $comment = $_POST['content'];
        $comment_id = $_GET['commentID'];
        $commentUpdate = "UPDATE tbl_comments SET forum_comment='$comment' WHERE forum_commentID='$comment_id'"; 

        $commentUpdate_result = mysqli_query($connection, $commentUpdate)
            or die ("Error is query:".mysqli_error($connection));
    }


?>

2 个答案:

答案 0 :(得分:1)

这是因为提交表单后没有$ _GET变量。看起来应该是这样的:

<form action="commentEdit.php?commentID=<?php echo $commentId; ?>" method="post">

答案 1 :(得分:0)

尝试使用同时处理$_REQUEST变量

$_GET ,$_POST变量