2016-08-05 21 views
0

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...PHP:創建一些表格並提交<a href

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 然後選擇互聯網... 謝謝!

+0

另外,你的'onclick'內嵌javascript沒有close報價 – Rasclatt

+0

最後,內聯js的這個部分'document.forms [「form2」]'會和你的'onclick =''發生衝突,你需要轉義它們。 – Rasclatt

回答

0

我只是把鏈接變成一個按鈕,並提交正常。這可能是因爲你已經在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; 
} 
+0

謝謝,這個工作,但我仍然找到了一種方式提交與href的形式,所以它看起來像我想要的!:) – fabien

0

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

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

在你的第二個表單上,只是做相同的操作,但將其取消。

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

我不能使用這個,因爲$ id隨着每個沒收而變化...我需要像 fabien