Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中使用post将值从一个页面传递到另一个页面_Php_Mysql - Fatal编程技术网

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

在php中使用post将值从一个页面传递到另一个页面,php,mysql,Php,Mysql,大家好,我有一个列,它将代表该特定记录的编辑行。所以,当我点击编辑按钮时,它会通过GET将id值传递给下一页。但现在我想使用POST将该id传递到下一页 有谁能帮助我如何使用POST将it id值从一个页面传递到另一个页面吗 这是我的密码: <tbody> <?php global $DB; if ($_SESSION[ 'idnumber']==1 ) { $retval="SELECT * FROM md

大家好,我有一个
列,它将代表该特定记录的编辑行。所以,当我点击编辑按钮时,它会通过GET将id值传递给下一页。但现在我想使用POST将该id传递到下一页

有谁能帮助我如何使用POST将it 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>


你可以使用这个功能

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

@TarangP感谢您的编辑,您能帮我解决这个问题吗您使用过ajax/为什么要使用POST?GET更有意义。GET用于获取资源(如编辑页面)虽然POST用于发送服务器要处理的数据。是的,但因为如果我使用了在URL中获取其显示id。因此用户可以编辑id并进行更改,对吗?因此,我希望使用POSTNo。通过get发送id是非常标准的。编辑页需要检查用户是否允许编辑该id。