我想使用表单和提交按钮在数据库中插入值。假设用户单击提交按钮后,插入代码将通过更新用户选择的值(从下拉列表中选择的值和复选框)完美运行。但是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> </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> '.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
答案 0 :(得分:0)
检查带有名称和值的html代码,例如
<input type='submit' name = 'btnSave' value = 'btnSave' />