duanlei7101 2017-01-18 12:21
浏览 12

php如何将链接的ID发送到新页面

So I have this table of albums and when I want to add a album I also have to give the linked button a albumID which has to be inserted into my database. I don't know how to give it through the button or maybe I don't even need it does anyone of you know any solution for this ?

table of albums code :

$db = mysqli_connect($host, $user, $pass,$database);

if($db){

    $h.= "";
    $h.= "<form><table class='table table-striped table-hover'>";
    $h.= "<tr>";
    $h.= "<th>Nr.</th>";
    $h.= "<th>Albums</th>";
    $h.= "<th>Artiest</th>";
    $h.= "<th>Nummer</th>";
    $h.= "<th></th>";
    $h.='<ul class="nav nav-pills" role="tablist">';
    $h.="   <li role='presentation' class='active'><a href='http://localhost:8888/?action=album '>Albums<span class='badge'></span></a></li>";
    $h.='   <li role="presentation"><a href="http://localhost:8888/?action=songs">Songs</a></li>';
    //$h.='<input type="button" class="btn btn-primary style="float: right"><a href="http://localhost:8888/?action=add-album">';
    $h.= "<td style='text-align:right;'><a href='/?action=add-album&albumid=".$_GET['id']."' class='btn btn-primary'>VOEG TOE</a></td>";

    $h.='</ul>';
    $h.="<br>";
    $h.= "</tr>";   

    $sql = mysqli_query($db,"SELECT * FROM albums");
    $sql1 = mysqli_query($db,"SELECT * FROM artiesten");

    if($sql){

    if(mysqli_num_rows($sql)>0) {  //if you have some albums to print...

        while ($row = mysqli_fetch_assoc($sql)) {

            //start printing a row
            $h.= "<tr>";
            $h.= "<td>".$row['id']."</td>";
            $h.= "<td>".$row['albumName']."</td>";

            //now get the artiest for the album by querying the correct albumid
            $albumid = $row['id'];
            $sql1 = mysqli_query($db,"SELECT * FROM artiesten WHERE albumID = '$albumid' ");

            while ($row1 = mysqli_fetch_assoc($sql1)){

                 $h.= "<td>".$row1['artiest']."</td>";  //print the right artiest
            }

            $h.= "<td style='text-align:right;'><a href='/?action=show-songs&id=".$row['id']."'' class='btn btn-primary'>Zie nummers</a>&nbsp";
            $h.= "<style='text-align:right;'><a href='/?action=delete-album&id=".$row['id']."'' class='btn btn-danger'>VERWIJDER</a></td>";
            $h.= "</tr>";

        }   

        }else{

            echo "<tr>No Recore Found</tr>";

        }

        $h.= "</table></form>";

    echo $htop;
    echo $h;
    echo $hbot;

when I want to add a album code :

db = mysqli_connect($host, $user, $pass,$database);

    if($_GET['action2'] == "1"){

        mysqli_query($db, "INSERT INTO artiesten (artiest, albumID) VALUES ('".$_GET['artiestnaam']."')"); 
        mysqli_query($db, "INSERT INTO albums (albumName) VALUES ('".$_GET['albumnaam']."')");                   
        header("Location: /?action=album");

    }

    $h = "";
    $h.= "";

    $h.= "<form><input type='hidden' name='action' value='add-album'><input type='hidden' name='action2' value='1'><input type='hidden' name='id' value='".$_GET['id']."'><table class='table table-striped'>";
    $h.= "  <tr>";
    $h.= "      <td><b>Artiest naam</b></td>";
    $h.= "      <td><input type='text' name='artiestnaam' class='form-control' placeholder='Naam'></td>";
    $h.= "  </tr>";
    $h.= "  <tr>";
    $h.= "      <td><b>Album naam</b></td>";
    $h.= "      <td><input type='text' name='albumnaam' class='form-control' placeholder='Naam'></td>";
    $h.= "  </tr>";
    $h.= "  <tr>";
    $h.= "      <td colspan='2'><input class='btn btn-primary' type='submit' value='UPDATE'></td>";
    $h.= "  </tr>";
    $h.= "</table></form>";

    echo $htop;
    echo $h;
    echo $hbot;
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP