繁体   English   中英

为什么我的if(isset($ _ POST)不起作用?

[英]why did my if(isset($_POST) doesn't work?

我想使用表单和提交按钮在数据库中插入值。 假设是,在用户单击“提交”按钮之后,通过更新用户选择的值(下拉菜单和复选框中的值),插入代码将完美运行。 但是if(isset($_POST['btnSave']))显示在var_dump($_POST)而不是if循环内部。

<?php
    $varUsrGrpID = isset($_REQUEST["dduser"])?$_REQUEST["dduser"]:"";
    $varAction = isset($_REQUEST["action"])?$_REQUEST["action"]:"";

    if ($varAction == "savedata")
    {
        if(isset($_POST['btnSave']))
        { 
            $checkBox = implode(',', $_POST['namaMenu']);

            if(strlen($checkBox)>=0)
            {

                foreach($_POST['namaMenu'] as $checkBox)
                {
                        $strConvert = "select CAST ('Y' as char) as eg";
                        $rsconvert = odbc_exec($dbconnVOT,$strConvert);

                        if (odbc_fetch_row($rsconvert))
                        {
                            $convertID = odbc_result($rsconvert, "eg");
                        }
                        else
                        {
                            exit();
                        }


                        $strInsertData = "insert into tblMenuAkses
                            (usrgrpid, menuid, menuakses)
                             values
                            (".checknull($GLOBALS["varUsrGrpID"]).",'$checkBox',
                            $convertID)";


                        $rsInsert = odbc_exec($dbconnVOT,$strInsertData);

                        if(!$rsInsert)
                        {
                            writeErr($strInsertData,odbc_errormsg(),'skrinMenu.php',$ErrFilePath);
                            $msg = "error";
                        }
                        else
                        {
                            $msg = "Success";
                        }

                }
            }

        }
        else
        {
            var_dump($_POST);
        }

    }   

    ?>

    <script>

function sendData(varActionSed)
{

    if(document.getElementById("dduser").value=="")
    {
        alert("Please choose 'dduser'");
        document.getElementById("dduser").focus();
        return false;
    }


    document.getElementById("action").value=varActionSed;
    document.getElementById("frm1").submit();

}   

</script>
<form name="frm1" id="frm1" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>" enctype="multipart/form-data">
<input type="hidden" name="action" id="action" value="">
<table align= "center" border="0" cellspacing="0" cellpadding="2">
    <tr>&nbsp;</tr>
    <tr>
            <td width="170" height="20:px" valign="top"><b>User<font style="color:#ff0000">*</font></b></td>
            <td valign="top" align="center" width="15:px"><b>:</b></td>
            <td valign="top">

    <?php
    echo "<select name=\"dduser\" id=\"dduser\">";
    echo "<option value=\"\">Please choose</option>";
    $sqlGetUsrGrp = "SELECT * FROM tblUsrGrp";
    $rs = odbc_exec($dbconnVOT,$sqlGetUsrGrp);

    if ($rs)
    {
        while(odbc_fetch_row($rs))
        {
            echo "<option value=\"".odbc_result($rs,"UsrGrpID")."\" ".($varUsrGrpID==odbc_result($rs,"UsrGrpID")?"selected":"").">".odbc_result($rs,"UsrGrpNama")."</option>";
        }
    }
    else
    {
        echo "error - ".odbc_errormsg();
    }
    echo "</select>";
    ?>


            </td>

    </tr>

        <?php

        $varMenuIDSumm="";
        $strMenuID="select * from tblMenuAkses";
        $rsMenuID=odbc_exec($dbconnVOT, $strMenuID);
        $countMenuID=0;
        while(odbc_fetch_row($rsMenuID))
        {
            $countMenuID++; 
            if($countMenuID==1)
            {
                $varMenuIDSumm=odbc_result($rsMenuID,"MenuID");
            }
            else
            {
                $varMenuIDSumm.=",".odbc_result($rsMenuID,"MenuID");
            }
        }   


        $menuID=array();
        $menuID=implode(",",$varMenuID);
        $strGetMenu="select * from tblMenu where MenuNama != 'sokong' and menunama not in ('Daftar Lejer Mengikut Dana')";

        $rs=odbc_exec($dbconnVOT, $strGetMenu);
        if($rs)
        {
            while (odbc_fetch_row($rs))
            {
                echo '<tr><td>';
                echo '<input type="checkbox" name="namaMenu[]" id="namaMenu" value='.odbc_result($rs,"menuID").'><b>&nbsp;'.odbc_result($rs,"MenuNama").'</b>' ;
                echo '</td></tr>';

            }

        }   

        ?>

<tr>
    <center>
        <input type="button" name="btnSave" id="btnSave" onClick="javascript:sendData('savedata');" value = "submit">
    </center>   
</tr>

</table>
</form>

任何帮助都感激不尽 。 TQ

用名称和值检查您的html代码以提交,例如

 <input type='submit' name = 'btnSave' value = 'btnSave' />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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