<head>
<title>Menghapus data MySQL</title>
</head>
<body>
<?php
if (isset($_POST['hapus']))
{
$host = 'localhost';
$user = 'rooot';
$pass = '';
$koneksi = mysql_connect($host,$user,$pass);
if (!$koneksi)
{
die('Gagal koneksi:'.mysql_error());
}
$nrp =$_POST['nrp'];
$sql ="DELETE FROM data_mahasiswa".
"WHERE nrp= $nrp";
mysql_select_db('mahasiswa');
$hapusdata = mysql_query($sql, $koneksi);
if (!$hapusdata)
{
die('Gagal hapus data:'.mysql_error());
}
echo "Berhasil hapus data\n";
mysql_close($koneksi);
}
else{
?>
<form method="post" action="index3.php">
<table width="500" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">nrp</td>
<td><input name="nrp" type="text" id="nrp"></td>
</tr>
<tr>
<td width="100"></td>
<td></td>
</tr>
<tr>
<input name="hapus" type="submit" id="hapus" value="Delete">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
Tidak ada komentar:
Posting Komentar