0
我想通過表單和提交按鈕在數據庫中插入值,假設用戶點擊提交按鈕後,插入代碼會通過更新(從下拉列表和複選框值)用戶有選擇的價值觀完美運行,但if(isset($_POST['btnSave']))
在var_dump($_POST)
而不是裏面,如果循環是顯示器。
<?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
你可以添加'var_dump'結果嗎?也許這是'行動',它沒有設置爲'saveData'或其他東西。 –
@ rap-2-h var dump result:'array(3){[「action」] => string(8)「savedata」[「ddKumpPenguna」] => string(1)「4」[「namaMenu」] => array(1){[0] => string(1)「4」}}',這就是'var_dump'結果。結果好像代碼沒有問題。我不知道什麼是錯的,爲什麼我的代碼不更新數據庫中的值 – Diyana