Membuat 2 atau Lebih Form pada Satu File | PHP
Seperti
File 1
<form name="projek_darat" method="post" action="pro_dar.php">
<input type="text" name="Projek Darat" />
<input type="submit" value="Submit" />
</form>File 2
<form name="projek_laut" method="post" action="pro_lau.php">
<input type="text" name="Projek Laut" />
<input type="submit" value="Submit" />
</form> dan
Input file 1
<?php
mysql_query("INSERT INTO naval VALUES (..,..)")
?>
Input file 2
<?php
mysql_query("INSERT INTO roken VALUES (..,..)")
?>Untuk lebih efisiennya,
File 1
<form name="projek_darat" method="post" action="pro_dar.php">
<input type="text" name="Projek Darat" />
<input type="submit" value="Submit" name="s1" />
</form>
<form name="projek_laut" method="post" action="pro_lau.php">
<input type="text" name="Projek Laut" />
<input type="submit" value="Submit" name="s2" />
</form>Input file 1
<?php
if(!empty($_POST['s1'])){
mysql_query("INSERT INTO naval VALUES (..,..)")
}
if(!empty($_POST['s2'])){
mysql_query("INSERT INTO roken VALUES (..,..)")
}
?>Kesimpulannya, Saya menambahkan
name pada submit, dan menggunakan metode if untuk mengecek form submit yang diklik.


Komentar
Posting Komentar