douya7121 2012-01-31 18:15
浏览 179

如何使用Javascript提交POST变量?

So I am trying to submit a variable and the name of the variable via a form. I switched a button from submit to button because I need additional validation.

Anyway, here's the button now:

<button type="button" onclick="subForm()" name="del" id="deletebutton" value="'.$org.'">Delete</button>

Here's my current validation:

<script type="text/javascript">
function subForm() 
{
    if(confirm("Are you sure you want to delete this?"))
        document.forms["addorg"].submit();
   else
       return false;

}
</script>

And here's my script on the other side:

if (isset($_POST["del"])  && ($_POST['del'] !== '')) {
    $del = mysql_real_escape_string(html2txt($_POST['del']));
    $resfile = mysql_query('SELECT file_loc from organization WHERE org_id = '.$del);
    $org_name = mysql_real_escape_string(html2txt($_POST['orgname']));

    if (!$resfile) 
        header('Location: '.$admin.'?error=query');

    while ($filerow = mysql_fetch_array($resfile)) {
        $fileplace = $filerow['file_loc'];
        unlink(".".$fileplace);
        rmdir($org_name);
    }

    mysql_query("DELETE from organization where org_id='".$del."'");
    header('Location: '.$admin);
}

It is not currently deleting the records that I want. How do I pass along the "del" name to the other page?

  • 写回答

4条回答 默认 最新

  • dongzilu0178 2012-01-31 18:26
    关注

    You can use <input type="hidden">:

    echo '<input type="hidden" name="org_id" value="'.$org_id.'" />'
    

    This should render something like:

    <input type="hidden" name="org_id" value="1" />
    

    Using this code you can access the hidden field data using:

    $org_id = $_POST['org_id'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?