Click here to Skip to main content
15,909,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Get dynamically generated textarea value on button submit in php
Posted

1 solution

XML
<?php
    $sql = 'SELECT * from newsmanagement order by dt desc';
    $ret=mysql_query($sql) or die(mysql_error());
    while($a=mysql_fetch_assoc($ret))
    {
    ?>
        <frame id="frame <?php echo $a; ?>">
        <form action="postcomment.php?bid=<?php echo $a[newsid]; ?>& txt=tid<?php echo $a[newsid]; ?>" method="post" onsubmit="return validate(this)" enctype="multipart/form-data">
        <table class="news-content" border="0" cellspacing="2" cellpadding="0">
            <tr class="headline">
                <th>
                 <?php echo $a[headline]; ?>
                </th>
            </tr>
            <tr class="summary">
                <td>
                <?php  echo $a[summary];  ?>
                </td>
            </tr>
            <tr class="postedby">
                <td style="text-align:right" height="auto">
                <b>Posted By:</b>
                <?php echo $a[postedby];?>
                </td>
            </tr>
            <?php
            // filter comments according to the Admin approval
            $sql_inner = "select comments from newscomments where newsid='$a[newsid]' and approved ='Activate'";
            $ret_inner=mysql_query($sql_inner) or die(mysql_error());
            while($b=mysql_fetch_assoc($ret_inner))
            {
            ?>
            <tr class="comment">
                <td style="text-align:left" height="auto">
                <b>Comments:</b>
                <?php echo $b[comments]; ?>
                <br>
                </td>
            </tr>
            <?php
            }
            ?>
            <tr>
                <td><div><b>Post Comments</b></div>
                    <textarea style="width:70%; " id="tid<?php echo $a[newsid] ?>" name="tid<?php echo $a[newsid] ?>"  rows="1" ></textarea>
                    <div><input class="btn" type="submit" id="<?php echo $a[newsid] ?>" name="Comments" value="Comments" ></div>
                </td>
            </tr>
        </table>
        <div class="seperator"></div>
        </form>
        </frame>
        <?php
        }
        ?>




// to get value
XML
$newsid= $_GET['bid'];
$comment= $_GET['txt'];
if($_POST[$comment] !='')
{
    $query = "insert into newscomments(dt,comments,newsid) values(SYSDATE(),'$_POST[$comment]',$newsid)";
    if(mysql_query($query))
    {
    ?>
        <script language="javascript" type="text/javascript">
        alert("You have successfully submitted the comments");
        location.href = "home.php";
        </script>
        <?php
    }
    else
    {
        ?>
        <script language="javascript" type="text/javascript">
        alert("Error on submit comment..!");
        location.href = "home.php";
        </script>
        <?php
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900