doulu4316 2017-07-30 13:06
浏览 176

如何在PHP中通过GET方法传递数据

I have created a page where admins of a site can see and edit their menu navigation items.. As you can see in this image:

print screen one

So each menu item has two links next to it.. One for deleting the menu item and the other one for updating it.

Basically what I did for updating the menu item is grabbing the id of that item and redirect it to another page called itemedit.php like this:

<a title='Edit' href='itemedit.php?i=$i'><span class='glyphicon glyphicon-pencil'></span></a>

And in the page itemedit.php I did this:

<?php 
if (isset($_GET['i'])){
    $i = $_GET['i'];
    $e = // The name that user entered
    $editItem = new Menus();

    if(isset($_POST['yes'])){
        $editItem->EditMenuItem($i,$e);
        echo '<META HTTP-EQUIV="Refresh" Content="0; URL=menus.php">';   
        exit; 
    }
    if(isset($_POST['no'])){
        echo '<META HTTP-EQUIV="Refresh" Content="0; URL=menus.php">';    
        exit; 
    }

    echo "
<section class='content' style='text-align:center;'>
                <form action='' method='POST'>
                    <h5><strong> 
                        Are you sure you want to edit the selected item ?</br></br>
                    </strong></h5>   
                    <p> 
                        <button name='yes' type='submit' class='btn btn-primary'>Yes</button>
                        <button name='no' type='submit' class='btn'>No</button>
                    </p> 
                </form> 
            </section>";

So if an admin clicked on "YES" , It should call the Menus class which goes like this:

I have skipped writing down the db connection and extra information in this class

<?php
class Menus{
    public function EditMenuItem($i,$e)
        {
            if(!empty($i))
            {
                $adm = $this->db->prepare("UPDATE menu_nav SET menu_link_$i =                  $e");
                $adm->bindParam(1,$i);
                $adm->execute();
            }
            else
            {
                header("Location: php/includes/errors/012.php");
                exit();
            }
        }
}
?>

Now the problem is I don't know how can I pass the data through the $e variable which contains the new edition of that menu item.

And because I have used a hyperlink rather than an input to redirect my page to itemedit.php, I cant pass a name attribute. So is there any way or solution to pass this data correctly in itemedit.php or no ?

<?php 
if (isset($_GET['i'])){
    $i = $_GET['i'];
    $e = // The name that user entered
    $editItem = new Menus();
  • 写回答

1条回答 默认 最新

  • dreamwind1985 2017-07-30 13:13
    关注

    You can store the data in the header of the get request.

    Have a look here: http://php.net/manual/en/function.headers-list.php

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法