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

时间:2018-06-13 05:38:42

标签: php mysql

大家好我有一个<td>列,它代表该特定记录的编辑行。因此,当我点击编辑时,它通过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>

任何人都可以帮我解决这个问题吗

提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以使用此功能

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; ?>'})">