douping5226 2013-10-07 21:22
浏览 136
已采纳

在URL中POST数据

In my page I have a table and I insert data into it from my DB with PHP. There are links in each row in the table. Each link directs the user to corresponding page. But these pages are like an exact copy of each other with just a small difference. A word.

Now that's stupid, to create bunch of pages for each link. Then change just a single word in them. Instead I want to create a single page. Post the data from the main page (in the url) and get the data (from url?) in the target page and do stuff. Well, I should just show do code:

<td class="align-left">
    <a href="artist.php?artist=<?php echo $row['Link'] ?>"><?php echo $row['Name'] ?></a>
</td>

This is the row I'm talking about. This loops through the DB and $row['Link'] changes every iteration. Generated code would look like this:

<td class="align-left">
    <a href="artist.php?artist=3doorsdown">3 Doors Down</a>
</td>

artist.php page includes this code at the top:

<?php include('vars/3doorsdown.php'); ?>

This 3doorsdown.php page includes some variables to be used in the page. What I want to do is get the 3doorsdown from the url (artist.php?artist=3doorsdown) and put it in the target page. Like this:

<?php
    $postData = /*parse url and get data */;
    include('vars/' .$postData. '.php');
?>

I don't know how to post and get data from url in php. So I need few pointers.

  • 写回答

2条回答 默认 最新

  • dporb84480 2013-10-07 21:28
    关注

    If your form on your webpage is using method="get", then use $_GET['variable'] to access the values of the querystring.

    <?php
        $artist = $_GET['artist'];
        echo $artist;
    ?>
    

    If you are using a method="post", then you would be using $_POST['artist'];

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误