Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //index.php
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Posting Multiple form dengan PHP</title>
- </head>
- <body>
- <form method="get" action="#">
- Jumlah form : <input type="text" size="5" name="jumlah" />
- <input type="submit" name="btnJumlah" value="OK" />
- </form>
- <form method="post" action="proses.php">
- <?php
- $jumlah=isset($_GET['jumlah'])?
- $_GET['jumlah']:0;
- if($jumlah){
- for($i=0; $i<$jumlah; $i++){
- $nomor = $i + 1;
- echo $nomor .". ";
- ?>
- jns kelamin :
- <label> Pria </label> <input type="radio" id="jk_<?php echo $nomor;?>a"
- name="jk[<?php echo $nomor;?>]"
- value="P" >
- <label> Wanita</label> <input type="radio" id="jk_<?php echo $nomor;?>b"
- name="jk[<?php echo $nomor;?>]"
- value="W" >
- <br />
- <?php
- }
- //cetak tombol jika inputan lebih dari 0
- }
- if($jumlah >0){ ?>
- <input type="submit" value="simpan" />
- <?php } ?>
- </form>
- </body>
- </html>
- //proses.php
- <?php
- //hitung jumlah form yang dikirim
- $jumlah = isset($_POST['jk'])?count($_POST['jk']):0;
- echo "<h1>Cetak semua form</h1>";
- for($i=0; $i<$jumlah; $i++){
- $urut = $i+1;
- $jk = $_POST['jk'][$i];
- //jika mau dimasukkan ke databases, silahkan buat query anda disini
- echo $urut." - ".$jk."<br />";
- }
- //salah penggunaan variabel ternyata
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement