普通网友 2016-08-05 01:14
浏览 74
已采纳

PHP:创建一些表单并使用<a href提交

Sorry for my spelling... Im trying to print a list of internets forfeit from my database and then when I click on the hyperlink, it send the id of the forfeit to the page.I have tried to put the id in a hidden value but nothing works, im truck there...

    include_once "DataBase/db.php";                 
    if($internet->num_rows != 0){
        while($rows = $internet->fetch_assoc()){
            $nom = $rows["nom"];
            $id = $rows["id"];
            $tech = $rows["technologie"];
            $telechargement = $rows["telechargement"];
            $televersement = $rows["televersement"];
            $utilisation = $rows["utilisation"];
            $prix= $rows["prix"];

            echo '
   <form name="form2" method="POST"     action="Fournisseurs/Videotron.php">
      <div class="boxes">
       <div class="[ price-option price-option--high ]">
        <div class="price-option__detail">
           <span class="price-option__cost">'.$nom.'<br>$'.$prix.'</span>
            </div>
            **<input type="hidden" name="id" value="'.$id.'"></input>
              <a href="Fournisseurs/Videotron.php" onclick="document.forms["form2"].submit(); class="price-option__purchase">Voir</a>** 
                </div>
                </div>
            </form>';
        }
}   

then on the second page, i would take the forfeit id to get the rest of data... if its not clear, you guys can see what im talking about here : http://fournisseursquebec.com/Forfaits.php then select internet... Thank you !

  • 写回答

2条回答 默认 最新

  • doushou3814 2016-08-05 15:23
    关注

    I would just turn the link into a button and submit normally. It's possible that you are running into malformation of your html by the way you have concatenated your string in PHP. You would need to do some escaping in your scenario. This is what you have:

    <!--                                                  wrong--v-----v missing---v                   -->
    <a href="Fournisseurs/Videotron.php" onclick="document.forms["form2"].submit(); class="price-option__purchase">Voir</a>
    

    Just change it to a button or submit and style it that way:

    include_once("DataBase/db.php");                 
    if($internet->num_rows != 0){
        while($rows = $internet->fetch_assoc()){
            $nom = $rows["nom"];
            $id = $rows["id"];
            $tech = $rows["technologie"];
            $telechargement = $rows["telechargement"];
            $televersement = $rows["televersement"];
            $utilisation = $rows["utilisation"];
            $prix= $rows["prix"];
    ?>
    <form name="form2" method="POST" action="Fournisseurs/Videotron.php">
        <div class="boxes">
            <div class="[ price-option price-option--high ]">
                <div class="price-option__detail">
                   <span class="price-option__cost"><?php echo $nom; ?><br>$<?php echo $prix; ?></span>
                </div>
                <input type="hidden" name="action" value="delete_id" />
                <input type="hidden" name="id" value="<?php echo $id; ?>" />
                **<div class="price-option__purchase">
                    <input type="submit" value="Voir" />
                </div>**
            </div>
        </div>
    </form>
    <?php
        }
    }
    

    Apply your css to the submit button.

    price-option__purchase input {
        background-color: red;
        color: #fff;
        display: block;
        width: 200px;
        height: 200px;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题