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 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图