[ASK] Tolongin salahnya dimana?


Status
Not open for further replies.

Peryoga

Beginner 1.0
maaf ini pertama kali saya posting soal pertanyaan ini. saya msh newbie untuk PHP baru seminggu ini coba2 PHP, punya basic programming aja biasa. tau sql dikit2.

ini saya lampirkan 2 filenya.

lihat.php

style="border:1px solid rgb(238,238,238); padding:10px; overflow:auto; width:1110px; height:375px;">
<h2 align="center"><font color="orange" size="6" face="arial"><b>Data Karyawan</b></font></h2><br>
<input type="button" value="Export To PDF" title="Save as PDF Format" onclick=window.open('report_data.php','_blank');><br><br>
<table width="1420" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#FFA800">
<th width="80">No</td>&nbsp;
<th width="100">NIK</td>&nbsp;
<th width="180">Nama</td>&nbsp;
<th width="80">Tempat Lahir</td>&nbsp;
<th width="90">Tanggal Lahir</td>&nbsp;
<th width="90">Pendidikan</td>&nbsp;
<th width="100">Asal Sekolah</td>&nbsp;
<th width="100">Jurusan</td>&nbsp;
<th width="50">Tahun Lulus</td>&nbsp;
<th width="120">No Telpon</td>&nbsp;
<th width="50">Jenis Kelamin</td>&nbsp;
<th width="70">Agama</td>&nbsp;
<th width="60">Status Kawin</td>&nbsp;
<th width="200">Pengalaman Kerja</td>&nbsp;
<th width="110">Ex - Bagian</td>&nbsp;
<th width="110">Ex - Departemen</td>&nbsp;
<th width="150">Reffrensi</td>&nbsp;
<th width="180">Action</td>&nbsp;
</tr>
<?php
$Open = mysql_connect("localhost","root","");
if (!$Open){
die ("Koneksi ke Engine MySQL Gagal !<br>");
}
$Koneksi = mysql_select_db("devdata");
if (!$Koneksi){
die ("Koneksi ke Database Gagal !");
}
$nomer=0;
$Cari="SELECT * FROM kary ORDER by NIK ";
$Tampil = mysql_query($Cari);
while ( $hasil = mysql_fetch_array ($Tampil)) {
$NIK = stripslashes ($hasil['NIK']);
$Nama = stripslashes ($hasil['Nama']);
$TempatLahir = stripslashes ($hasil['TempatLahir']);
$TglLahir = $hasil['TglLahir'];
$Pendidikan = stripslashes ($hasil['Pendidikan']);
$AsalSklh = stripslashes ($hasil['AsalSklh']);
$Jurusan = stripslashes ($hasil['Jurusan']);
$Thnlulus = stripslashes ($hasil['Thnlulus']);
$Notlp = stripslashes ($hasil['Notlp']);
$JK = stripslashes ($hasil['JK']);
$Agama = stripslashes ($hasil['Agama']);
$Status = stripslashes ($hasil['Status']);
$PKerja = stripslashes ($hasil['PKerja']);
$Exbag = stripslashes ($hasil['Exbag']);
$Exdept = stripslashes ($hasil['Exdept']);
$reff = stripslashes ($hasil['reff']);

{
$nomer++;
?>
<tr align="center" bgcolor="#DFE6EF">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>


</tr>
<tr align="center">
<td><?php echo $nomer?><div align="center"></div></td>
<td><?php echo $NIK?><div align="center"></div></td>
<td><?php echo $Nama?><div align="center"></div></td>
<td><?php echo $TempatLahir?><div align="center"></div></td>
<td><?php
if ($hasil['TglLahir'] === NULL)
$hasil['TglLahir'] = "NULL";
echo("$TglLahir\n");
?><div align="center"></div></td>
<td><?php echo $Pendidikan?><div align="center"></div></td>
<td><?php echo $AsalSklh?><div align="center"></div></td>
<td><?php echo $Jurusan?><div align="center"></div></td>
<td><?php echo $Thnlulus?><div align="center"></div></td>
<td><?php echo $Notlp?><div align="center"></div></td>
<td><?php echo $JK?><div align="center"></div></td>
<td><?php echo $Agama?><div align="center"></div></td>
<td><?php echo $Status?><div align="center"></div></td>
<td><?php echo $PKerja?><div align="center"></div></td>
<td><?php echo $Exbag?><div align="center"></div></td>
<td><?php echo $Exdept?><div align="center"></div></td>
<td><?php echo $reff ?><div align="center"></div></td>
<td bgcolor="#EEF2F7"><div align="center"><a href="index.php?page=detail&nik=<?php echo $NIK?>">Detail</a> | <a href="index.php?page=delete&nik=<?php echo $NIK?>" OnClick="return confirm('Anda Yakin Seluruh Data Karyawan <?php echo $NIK?> Atas Nama <?php echo $Nama?> akan dihapus?');">Delete</a></div></td>
</tr>
<tr align="center" bgcolor="#DFE6EF">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>

</tr>
<?php
}
}
//Tutup koneksi engine MySQL
mysql_close($Open);
?>
</table>
</div>

delete.php
<?php
//koneksi ke engine mysql
$Open = mysql_connect("localhost","root","");
if (!$Open){
die ("Koneksi ke Engine MySQL Gagal !<br>");
}
$Koneksi = mysql_select_db("devdata");
if (!$Koneksi){
die ("Koneksi ke Database Gagal !");
}
// Cek nik
if (isset($_GET['NIK'])) {
$NIK = $_GET['NIK'];
// membaca nama file yang akan dihapus
$query = "SELECT * FROM kary WHERE nik='$NIK'";
$hasil = mysql_query($query);
}
else {
die ("Error. Tidak ada Nik yang dipilih Silakan cek kembali! ");
}
//proses hapus data
if (!empty($NIK) && $NIK != "") {
$hapus = "DELETE FROM kary WHERE nik='$NIK'";
$sql = mysql_query ($hapus);
if ($sql) {
?>
<script language="JavaScript">
alert('Seluruh Data Karyawan <?php=$NIK?> Berhasil dihapus!');
document.location='index.php?page=lihat';
</script>
<?php
} else {
echo "<h2><font color=red><center>Data Karyawan gagal dihapus</center></font></h2>";
}
}
//Tutup koneksi engine MySQL
mysql_close($Open);
?>
setiap saya coba delete, yg terjadi adalah error, tidak ada NIK yang di pilih. padahal klo saya liat dr proses GET-nya sudah ke ambil datanya.

Mohon bantuannya....
 

HostingMU.Net

Apprentice 1.0
Maaf kalo saya sendiri bingung bacanya, Coba sertakan Screenshot coding yg ada di Text Editor seperti Sublime/Netbeans :D biar eyecatching :D
 

Peryoga

Beginner 1.0
ini mas saya sertakan screenshot codingnya

mohon bantuannya
 

Attachments

  • 2.JPG
    2.JPG
    152.9 KB · Views: 25
  • 1.JPG
    1.JPG
    119.5 KB · Views: 25
  • 3.JPG
    3.JPG
    72.7 KB · Views: 22

HostingMU.Net

Apprentice 1.0
maaf ini pertama kali saya posting soal pertanyaan ini. saya msh newbie untuk PHP baru seminggu ini coba2 PHP, punya basic programming aja biasa. tau sql dikit2.

ini saya lampirkan 2 filenya.

lihat.php

style="border:1px solid rgb(238,238,238); padding:10px; overflow:auto; width:1110px; height:375px;">
<h2 align="center"><font color="orange" size="6" face="arial"><b>Data Karyawan</b></font></h2><br>
<input type="button" value="Export To PDF" title="Save as PDF Format" onclick=window.open('report_data.php','_blank');><br><br>
<table width="1420" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#FFA800">
<th width="80">No</td>&nbsp;
<th width="100">NIK</td>&nbsp;
<th width="180">Nama</td>&nbsp;
<th width="80">Tempat Lahir</td>&nbsp;
<th width="90">Tanggal Lahir</td>&nbsp;
<th width="90">Pendidikan</td>&nbsp;
<th width="100">Asal Sekolah</td>&nbsp;
<th width="100">Jurusan</td>&nbsp;
<th width="50">Tahun Lulus</td>&nbsp;
<th width="120">No Telpon</td>&nbsp;
<th width="50">Jenis Kelamin</td>&nbsp;
<th width="70">Agama</td>&nbsp;
<th width="60">Status Kawin</td>&nbsp;
<th width="200">Pengalaman Kerja</td>&nbsp;
<th width="110">Ex - Bagian</td>&nbsp;
<th width="110">Ex - Departemen</td>&nbsp;
<th width="150">Reffrensi</td>&nbsp;
<th width="180">Action</td>&nbsp;
</tr>
<?php
$Open = mysql_connect("localhost","root","");
if (!$Open){
die ("Koneksi ke Engine MySQL Gagal !<br>");
}
$Koneksi = mysql_select_db("devdata");
if (!$Koneksi){
die ("Koneksi ke Database Gagal !");
}
$nomer=0;
$Cari="SELECT * FROM kary ORDER by NIK ";
$Tampil = mysql_query($Cari);
while ( $hasil = mysql_fetch_array ($Tampil)) {
$NIK = stripslashes ($hasil['NIK']);
$Nama = stripslashes ($hasil['Nama']);
$TempatLahir = stripslashes ($hasil['TempatLahir']);
$TglLahir = $hasil['TglLahir'];
$Pendidikan = stripslashes ($hasil['Pendidikan']);
$AsalSklh = stripslashes ($hasil['AsalSklh']);
$Jurusan = stripslashes ($hasil['Jurusan']);
$Thnlulus = stripslashes ($hasil['Thnlulus']);
$Notlp = stripslashes ($hasil['Notlp']);
$JK = stripslashes ($hasil['JK']);
$Agama = stripslashes ($hasil['Agama']);
$Status = stripslashes ($hasil['Status']);
$PKerja = stripslashes ($hasil['PKerja']);
$Exbag = stripslashes ($hasil['Exbag']);
$Exdept = stripslashes ($hasil['Exdept']);
$reff = stripslashes ($hasil['reff']);

{
$nomer++;
?>
<tr align="center" bgcolor="#DFE6EF">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>


</tr>
<tr align="center">
<td><?php echo $nomer?><div align="center"></div></td>
<td><?php echo $NIK?><div align="center"></div></td>
<td><?php echo $Nama?><div align="center"></div></td>
<td><?php echo $TempatLahir?><div align="center"></div></td>
<td><?php
if ($hasil['TglLahir'] === NULL)
$hasil['TglLahir'] = "NULL";
echo("$TglLahir\n");
?><div align="center"></div></td>
<td><?php echo $Pendidikan?><div align="center"></div></td>
<td><?php echo $AsalSklh?><div align="center"></div></td>
<td><?php echo $Jurusan?><div align="center"></div></td>
<td><?php echo $Thnlulus?><div align="center"></div></td>
<td><?php echo $Notlp?><div align="center"></div></td>
<td><?php echo $JK?><div align="center"></div></td>
<td><?php echo $Agama?><div align="center"></div></td>
<td><?php echo $Status?><div align="center"></div></td>
<td><?php echo $PKerja?><div align="center"></div></td>
<td><?php echo $Exbag?><div align="center"></div></td>
<td><?php echo $Exdept?><div align="center"></div></td>
<td><?php echo $reff ?><div align="center"></div></td>
<td bgcolor="#EEF2F7"><div align="center"><a href="index.php?page=detail&nik=<?php echo $NIK?>">Detail</a> | <a href="index.php?page=delete&nik=<?php echo $NIK?>" OnClick="return confirm('Anda Yakin Seluruh Data Karyawan <?php echo $NIK?> Atas Nama <?php echo $Nama?> akan dihapus?');">Delete</a></div></td>
</tr>
<tr align="center" bgcolor="#DFE6EF">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>

</tr>
<?php
}
}
//Tutup koneksi engine MySQL
mysql_close($Open);
?>
</table>
</div>

delete.php
<?php
//koneksi ke engine mysql
$Open = mysql_connect("localhost","root","");
if (!$Open){
die ("Koneksi ke Engine MySQL Gagal !<br>");
}
$Koneksi = mysql_select_db("devdata");
if (!$Koneksi){
die ("Koneksi ke Database Gagal !");
}
// Cek nik
if (isset($_GET['NIK'])) {
$NIK = $_GET['NIK'];
// membaca nama file yang akan dihapus
$query = "SELECT * FROM kary WHERE nik='$NIK'";
$hasil = mysql_query($query);
}
else {
die ("Error. Tidak ada Nik yang dipilih Silakan cek kembali! ");
}
//proses hapus data
if (!empty($NIK) && $NIK != "") {
$hapus = "DELETE FROM kary WHERE nik='$NIK'";
$sql = mysql_query ($hapus);
if ($sql) {
?>
<script language="JavaScript">
alert('Seluruh Data Karyawan <?php=$NIK?> Berhasil dihapus!');
document.location='index.php?page=lihat';
</script>
<?php
} else {
echo "<h2><font color=red><center>Data Karyawan gagal dihapus</center></font></h2>";
}
}
//Tutup koneksi engine MySQL
mysql_close($Open);
?>
setiap saya coba delete, yg terjadi adalah error, tidak ada NIK yang di pilih. padahal klo saya liat dr proses GET-nya sudah ke ambil datanya.

Mohon bantuannya....
Koneksi databasenya sdh benar ?
 

Novan

Poster 2.0
Coba ini
Pada code
Code:
// Cek nik
if (isset($_GET['NIK'])) {

ganti dengan
Code:
// Cek nik
if (isset($_GET['nik'])) {

Penamaan parameter itu Case sensitive, jadi harus sama Setter dan Getter nya, jika tdk sesuai ya kondisinya masuk ke statement ELSE terus.
 

Peryoga

Beginner 1.0
Coba ini
Pada code
Code:
// Cek nik
if (isset($_GET['NIK'])) {

ganti dengan
Code:
// Cek nik
if (isset($_GET['nik'])) {

Penamaan parameter itu Case sensitive, jadi harus sama Setter dan Getter nya, jika tdk sesuai ya kondisinya masuk ke statement ELSE terus.

saya sudah coba untuk ganti parameter setter ama getternya. namun hasilnya masil tetap sama. semoga ada jawaban atas pertanyaan saya yah... bingung pisan...
 

Novan

Poster 2.0
Coba ini delete.php nya pakai ini , saya ubah di Line 12,13 dan 28
Code:
<?php
//koneksi ke engine mysql
$Open = mysql_connect("localhost","root","");
if (!$Open){
die ("Koneksi ke Engine MySQL Gagal !<br>");
}
$Koneksi = mysql_select_db("devdata");
if (!$Koneksi){
die ("Koneksi ke Database Gagal !");
}
// Cek nik
if (isset($_GET['nik'])) {
$NIK = $_GET['nik'];
// membaca nama file yang akan dihapus
$query = "SELECT * FROM kary WHERE nik='$NIK'";
$hasil = mysql_query($query);
}
else {
die ("Error. Tidak ada Nik yang dipilih Silakan cek kembali! ");
}
//proses hapus data
if (!empty($NIK) && $NIK != "") {
$hapus = "DELETE FROM kary WHERE nik='$NIK'";
$sql = mysql_query ($hapus);
if ($sql) {
?>
<script language="JavaScript">
alert('Seluruh Data Karyawan <?=$NIK?> Berhasil dihapus!'); 
document.location='index.php?page=lihat';
</script>
<?php
} else {
echo "<h2><font color=red><center>Data Karyawan gagal dihapus</center></font></h2>";
}
}
//Tutup koneksi engine MySQL
mysql_close($Open);
?>

Saya test sudah bisa sih, di file Lihat.php nya biarkan saja setternya tetep ?nik=
 

Attachments

  • Screen Shot 2016-06-14 at 8.36.23 AM.png
    Screen Shot 2016-06-14 at 8.36.23 AM.png
    289.7 KB · Views: 3
Status
Not open for further replies.

Top