在php中使用post将值从一个页面传递到另一个页面

ujv3wf0j  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(362)

嗨伙计们我有一个 <td> 列,它将代表该特定记录的编辑行。因此,当我单击edit时,它通过get将id值传递给下一页。但现在我想用post把这个id传递到下一页。
有谁能帮我用post把它的id值从一个页面传递到另一个页面吗
这是我的密码:

<tbody>
    <?php 
        global $DB; 
        if ($_SESSION[ 'idnumber']==1 ) { 
            $retval="SELECT * FROM mdl_ppc_company mpc  where status='1' ORDER BY mpc.cid " ; 
        } 
        $companydeactivate = $DB->get_records_sql($retval); 
        if (sizeof($companydeactivate)): 
            foreach ($companydeactivate as $row): 
                if ($_SESSION['idnumber'] == 3 && $row->idnumber == 3) 
                { 
                    continue; 
                } 
                else { ?>
    <tr class="gradeX">
        <td>
            <?php echo $row->company; ?></td>
        <td>
            <?php echo $row->createdby; ?></td>
        <td>
            <center>
                <a href="editcompany.php">
                    <img src="images/header_icon/Icon_10.png" style="background-color:teal; width:25px; height:25px; border-radius: 4px" alt="edit_btn">
                </a>
            </center>
        </td>
        <?php if ($row->level == '1') { ?>
        <td>
            <center>
                <a href="companydeactivate.php?id=<?php echo $row->cid; ?>" onclick="" class="disabled">
                    <img src="images/header_icon/icon_delete.png" style="background-color:#c30c0c; width:25px; height:25px; border-radius: 4px" alt="delete_btn">
                </a>
            </center>
        </td>
        <?php } else { ?>
        <td>
            <center>
                <a href="companydeactivate.php?id=<?php echo $row->cid; ?>" onclick="">
                    <img src="images/header_icon/icon_delete.png" style="background-color:#c30c0c; width:25px; height:25px; border-radius: 4px" alt="delete_btn">
                </a>
            </center>
        </td>
        <?php } ?>
    </tr>
    <?php } endforeach; endif; ?>
</tbody>

有人能帮我解决这个问题吗
提前谢谢。

vh0rcniy

vh0rcniy1#

你可以使用这个函数

function post(path, params, method) {
    method = method || "post"; // Set method to post by default if not specified.

    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);

    for(var key in params) {
        if(params.hasOwnProperty(key)) {
            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", key);
            hiddenField.setAttribute("value", params[key]);

            form.appendChild(hiddenField);
        }
    }

    document.body.appendChild(form);
    form.submit();
}

例子

<img src="images/header_icon/Icon_10.png" style="background-color:teal; width:25px; height:25px; border-radius: 4px" 
alt="edit_btn" onclick="post('editcompany.php', {id: '<?php echo $row->cid; ?>'})">

相关问题