Search code examples
phphtml

Value not posted when click on submit in php


Simple php code to post a value and echo it inside if(isset()), when click on submit button, but it's not working.

<?php
    if(isset($_GET['q']))
    {
        $q=$_GET['q'];
        //echo "thisss iss qqqq".$q; this is working
        $_SESSION['q']=$q;

        if($q=="1")
        {
        ?>
            <form action='#'>
                <tr>
                    <input type='text' name='txt_code' >
                    <input type='submit' name='code_sub' value='Showcd'>
                </tr>
            </form>
        <?php
        }

//here I wrote code for to echo $bkCode when click on 'showcd' button but it's not working

<?php
    if (isset($_POST["code_sub"]))
    {
        echo $bkCode=$_POST['txt_code']; // THIS IS NOT WORKING
    } 

}
?>

It doesn't even enter inside the if (isset($_POST["code_sub"])) part


Solution

  • Default action of a form is GET. You have to specify that u want to do a POST :

    <form action="#" method="POST">