Advertisement
GWibisono

variabel yg dipake salah

Feb 16th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //index.php
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.  
  5. <title>Posting Multiple form dengan PHP</title>
  6. </head>
  7.  
  8. <body>
  9.  
  10.  
  11. <form method="get" action="#">
  12.     Jumlah form : <input type="text" size="5" name="jumlah" />
  13.     <input type="submit" name="btnJumlah" value="OK" />
  14. </form>
  15.  
  16.  
  17. <form method="post" action="proses.php">
  18. <?php
  19. $jumlah=isset($_GET['jumlah'])?
  20. $_GET['jumlah']:0;
  21.  
  22. if($jumlah){
  23.  
  24. for($i=0; $i<$jumlah; $i++){
  25. $nomor = $i + 1;
  26. echo $nomor .". ";
  27. ?>
  28.  
  29. jns kelamin :
  30. <label> Pria </label> <input type="radio" id="jk_<?php echo $nomor;?>a"
  31.     name="jk[<?php echo $nomor;?>]"
  32.     value="P" >
  33. <label> Wanita</label> <input type="radio" id="jk_<?php echo $nomor;?>b"
  34.     name="jk[<?php echo $nomor;?>]"
  35.     value="W" >
  36. <br />
  37. <?php
  38. }
  39. //cetak tombol jika inputan lebih dari 0
  40.     }
  41.     if($jumlah >0){ ?>
  42. <input type="submit" value="simpan" />
  43.     <?php } ?>
  44.  
  45. </form>
  46. </body>
  47. </html>
  48.  
  49. //proses.php
  50. <?php
  51.  
  52. //hitung jumlah form yang dikirim
  53. $jumlah = isset($_POST['jk'])?count($_POST['jk']):0;  
  54.  
  55.     echo "<h1>Cetak semua form</h1>";
  56.  for($i=0; $i<$jumlah; $i++){
  57.     $urut   = $i+1;
  58.    
  59.     $jk = $_POST['jk'][$i];
  60.  
  61.     //jika mau dimasukkan ke databases, silahkan buat query anda disini
  62.     echo $urut." - ".$jk."<br />";
  63.  }
  64.  //salah penggunaan variabel ternyata
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement