简体   繁体   中英

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

I want to insert values in the database by using form and submit button. It suppose to be that, after user click the submit button, the insert code will be run perfectly by updating the values that user have choose (value from dropdown and checkbox). But the if(isset($_POST['btnSave'])) was display at var_dump($_POST) instead of inside if loops.

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

Any help will be much appreciated . TQ

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

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

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