在 php 中单击提交时未发布值

问题描述 投票:0回答:3

单击提交按钮时发布值并在 if(isset()) 内回显它的简单 php 代码,但它不起作用。

<?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
        }

//这里我编写了当单击“showcd”按钮时回显 $bkCode 的代码,但它不起作用

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

}
?>

它甚至没有进入

if (isset($_POST["code_sub"]))
部分内部

php html
3个回答
3
投票

表单的默认操作是

GET
。您必须指定您想要进行 POST :

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

0
投票

首先,您应该设置 var,然后是一个简单的输出:

<?php

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

?>

还需要将表单方法设置为“POST”!

<form action='the_link' method="POST">

0
投票

对于使用post方法:

<form action='the_link' method="POST">
© www.soinside.com 2019 - 2024. All rights reserved.