user2957160
user2957160

Reputation: 13

1 help, undefined index when retrieving a GET variable

I am trying to retrieve the $_GET variable but it keeps telling me that I have an undefined index as if the variable wasn't stored.

<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));
    }


?>

Upvotes: 0

Views: 62

Answers (2)

Muhammad Rashid
Muhammad Rashid

Reputation: 583

Try to user $_REQUEST variable which is handle both $_GET ,$_POST variable

Upvotes: 0

Markus Kottl&#228;nder
Markus Kottl&#228;nder

Reputation: 8268

It is because there is no $_GET variable after submitting your form. It shoul look something like this:

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

Upvotes: 1

Related Questions