Hello,

I keep having this error whenever I try to post a reply on my forum website. Here is my code:

<?php
    session_start();

    include ('dbconn.php');

    $comment = nl2br(addslashes($_POST['comment']));
    $cid = $_GET['cid'];
    $scid = $_GET['scid'];
    $tid = $_GET['tid'];

    $insert = mysqli_query($con, "INSERT INTO replies (`category_id`, `subcategory_id`, `topic_id`, `author`, `comment`, `date_posted`)
                                  VALUES ('".$cid."', '".$scid."', '".$tid."', '".$_SESSION['username']."', '".$comment."', NOW());");

    if ($insert) {
        header("Location: /forum-tutorial/readtopic/".$cid."/".$scid."/".$tid."");
    }
?>

I have tried to solve this but have no clue. I am still new in php. I would really appriciate it to get eny help from experts out there. Thanks guys!

Hi,

the error is telling you the index key cid does not exists in the $_GET array. So, are you submitting the cid attribute through the form or through the action link? I mean, like this:

<form action="script.php" method="post">
    <input type="hidden" name="cid" value="123">

or like this?

<form action="script.php?cid=123" method="post">

By using $_GET the cid key should arrive to the script through the query string ?cid=123, if instead it's inside an input tag, then change it to $_POST:

$cid = $_POST['cid'];

Note: it's always a good practice to check if the expected keys are set and if they are transmitting the expected input. Use filter_input() to validate and sanitize the input, read:

Bye!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.