dongliling6336 2014-10-21 10:29
浏览 35
已采纳

$ _GET方法偶尔不传递任何数据。

so I have been building a small website with a content management system I have built using PHP and mysql. What I am trying to achieve is the user needs to be able to edit and delete the announcement posts they make, so I have been using $_GET to get the ID of the post that is to be edited/ deleted and chucked into a form which holds the code to do that.

Now, this is the code I have been using

if(isset($_GET['edit'])) {
    header('Location: announcement-edit.php?AnnouncementID='.$_GET['AnnouncementID']);  
}       

The form later down the page to execute this is as follows

<form action="announcements.php" method="get">

<input type="hidden" name="AnnouncementID" value="<?php echo $row['AnnouncementID'];?>" />
    <input name="edit" value="Modify" type="submit">
    <input name="delete" value="Delete" type="submit" >
    </form>   

This is where it confuses me, this code worked absolutely perfectly then all of a sudden last week it stopped, 2 days ago it started working again and now broken again. When the button is clicked the URL returns as;

url/folder/announcements.php?AnnouncementID=7&edit=Modify

When its supposed to return;

url/folder/announcement-edit.php?AnnouncementID=7

If i manually type the above in the url bar it works absolutely fine and I can update the rows in the DB.

Im totally stumped as to why it is so temperamental, Have I missed something out? am I trying to do this an out dated way?

Its not like I have just followed a random person on youtube how to do this I was actually shown this way at university (only last academic year) and we was told it was "good practice". Seems very weird it works perfectly one minute then refuses to work the next.

Any thoughts or suggestions will be greatly appreciated.

  • 写回答

2条回答 默认 最新

  • dongmaobeng7145 2014-10-21 10:39
    关注

    You dont need to use form. You can do it simply using url and use tag Try to pass your parametr via get parametr like this:

    <a href="announcements.php?AnnouncementID=<?php echo $row['AnnouncementID'];?>&edit=1">Edit</a>
    <a href="announcements.php?AnnouncementID=<?php echo $row['AnnouncementID'];?>&delete=1">Delete</a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划