简体   繁体   中英

$_POST doesn't work for PHP post. ISSET reports that no such value was forwared via post method?

I have a form for a comment section. Here every comment has unique IDs. But however, the comments aren't forwarded to the action PHP form.

Code for comments:

    echo '<form action="interact.php" method="post">';
    $new_refreshed_ID = 'uni_story_ID_' . $row['ID'] . '_comment_ID_' . $cache_ready_new_comment_ID;
    echo '<textarea name="' . $new_refreshed_ID . 'rows="12" cols="70"></textarea>';
    echo '<button type="submit">Submit</button>';
    echo '</form>';
$_SESSION['assoc'] = $row['ID'];
$_SESSION['cache_comment_details'] = $new_refreshed_ID;

My code for receiving the request: interact.php:

<?php
session_start();


    $assoc = $_SESSION['assoc'];
                $get_comment = $_SESSION['cache_comment_details'];

                if(isset($_POST[$get_comment])) {
                    echo "yea!";
                } else {
                    echo "no!";
                    die();
                }

I get no in the interact.php which means that no data was forwarded. How can this be?

btw comment id's are in this manner (for example):

uni_story_ID_4_comment_ID_17

I did check $new_refreshed_ID. It is showing all the values properly as desired. I did start the sessions in the both PHP files.

echo '<textarea name="' . $new_refreshed_ID . 'rows="12" cols="70"></textarea>';

You need to close the name of textarea like this:

echo '<textarea name="' . $new_refreshed_ID . '" rows="12" cols="70"></textarea>';

Edit: Even Better to not use php when not needed (to avoid those) you can maybe do something like this:

<textarea name="<?php print $new_refreshed_ID;?>" rows="12" cols="70"></textarea>

Please note that this is an Example, i'm only printing what is really needed with php, otherwise i'll stay with html :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM