Monday, November 29, 2010

Let Learn PHP (Basic) - Lesson 5

Here's the code to Delete Multiple table at once...



<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'my_db';
$editFormAction = $_SERVER['PHP_SELF'];
if ((isset($_POST["Delete"])) && ($_POST["Delete"] == "Hapus")) {
mysql_select_db($dbname, $conn);
mysql_query("DELETE FROM biodata_ahli WHERE nokp_baru='".$_POST['nokp_baru']."'", $conn)or die(mysql_error());
mysql_query("DELETE FROM pengguna WHERE nokp_baru='".$_POST['nokp_baru']."'", $conn)or die(mysql_error());
}
mysql_select_db($dbname,$conn);
$query_pengguna = "SELECT pengguna.nokp_baru, pengguna.id_pengguna, biodata_ahli.nama FROM pengguna LEFT JOIN biodata_ahli ON biodata_ahli.nokp_baru = pengguna.nokp_baru WHERE pengguna.nokp_baru = '121212121212'";
$pengguna = mysql_query($query_pengguna, $conn) or die(mysql_error());
$row_pengguna = mysql_fetch_assoc($pengguna);
$totalRows_pengguna = mysql_num_rows($pengguna);
?>
<form name="form1" method="post" action="<?php echo $editFormAction; ?>">
<table border="1" bordercolor="#000000" align="center">
<tr><td>
<table width="365" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="131">Nama</td>
<td width="10">:</td>
<td width="224"><?php echo $row_pengguna['nama']; ?></td>
</tr>
<tr>
<td>No. Kad Pengenalan</td>
<td>:</td>
<td><?php echo $row_pengguna['nokp_baru']; ?>
<input name="nokp_baru" type="hidden" value="<?php echo $row_pengguna['nokp_baru']; ?>"></td>
</tr>
<tr>
<td>ID Pengguna</td>
<td>:</td>
<td><?php echo $row_pengguna['id_pengguna']; ?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Delete" id="Delete" value="Hapus"></td>
</tr>
</table>
</td></tr></table>
</form>





Pretty easy is it?

3 comments:

LinkWithin

Related Posts Plugin for WordPress, Blogger...