簡體   English   中英

PHP:創建一些表單並提交給

[英]PHP : Create some form and submit it with <a href

對不起,我的拼寫...我試圖打印從我的數據庫中被沒收的互聯網列表,然后當我單擊超鏈接時,它會將被沒收的ID發送到頁面。我試圖將ID設為隱藏值但是什么都沒用,我在那兒卡車...

    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>';
        }
}   

然后在第二頁上,我將使用沒收的ID來獲取其余數據...如果不清楚,你們可以在這里看到我正在談論的內容: http : //fournisseursquebec.com/Forfaits.php,然后選擇Internet ... 謝謝 !

這可能是最佳解決方案,也可能不是最佳解決方案,但是您可以為此使用會話。 將其放在while循環中。

<?php
session_start();
$_SESSION['id'] = $id;
?>

在您的第二種形式上,請執行相同的操作,但要相反。

<?php
session_start();
$id = $_SESSION['id'];
?>

我只是將鏈接變成一個按鈕,然后正常提交。 通過在PHP中串聯字符串的方式,您可能會遇到html格式錯誤的情況。 您需要在方案中進行一些轉義。 這是您所擁有的:

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

只需將其更改為按鈕或以這種方式提交並設置其樣式即可:

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
    }
}

將您的CSS應用於提交按鈕。

price-option__purchase input {
    background-color: red;
    color: #fff;
    display: block;
    width: 200px;
    height: 200px;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM