Postingan lainnya
Koding php error
nama file : index.php
?php
include_once “koneksi.php”;
?>
<table class=”ui celled striped table”>
<thead>
<tr>
<th colspan=”5″>
Git Repository
</th>
</tr>
</thead>
<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>Jenis Kelamin</th>
<th>Kota</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$select = $koneksi->prepare(“SELECT id, nama, kota, jenis_kelamin FROM penduduk”);
$select->execute();
$select->store_result();
$select->bind_result($db_id, $db_nama, $db_kota, $db_kelamin);
while($select->fetch())
{
?>
<tr>
<td class=”collapsing”><?= $i++; ?></td>
<td><?= $db_nama; ?></td>
<td><?= $db_kelamin; ?></td>
<td><?= $db_kota; ?></td>
<td class=”collapsing”>
<a href=”delete.php?id=<?= $db_id; ?>” class=”ui red mini icon button”>
<i class=”remove icon”></i>
</a>
<a href=”edit.php?id=<?= $db_id; ?>” class=”ui green mini icon button”>
<i class=”edit icon”></i>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
nama file : koneksi.php
<?php
$koneksi = new mysqli(“localhost”, “root”, “”, “crud”);
//Jika Koneksi Gagal
if(mysqli_connect_errno())
{
trigger_error(“Tidak Dapat Terkoneksi Dengan Database”);
}
$koneksi->set_charset(‘UTF-8’);
?>
nama file : tambah.php
<form class=”ui form” action=”prosess-tambah.php” method=”post”>
<div class=”field”>
<label>Nama</label>
<input name=”nama” placeholder=”Nama Anda” type=”text”>
</div>
<div class=”field”>
<label>Jenis Kelamin</label>
<select class=”ui dropdown” name=”kelamin”>
<option value=””>Select</option>
<option value=”Laki – laki”>Laki – Laki</option>
<option value=”Perempuan”>Perempuan</option>
</select>
</div>
<div class=”field”>
<label>Kota</label>
<input name=”kota” placeholder=”Kota Anda” type=”text”>
</div>
<button class=”ui button blue” type=”submit”>Tambah</button>
</form>
nama file : prosses-tambah.php
<?php
include_once “koneksi.php”;
$nama = $_POST[‘nama’];
$jenis_kelamin = $_POST[‘kelamin’];
$kota = $_POST[‘kota’];
$insert = $koneksi->prepare(“INSERT INTO `penduduk` (`nama`, `jenis_kelamin`, `kota`) VALUES (?, ?, ?)”);
$insert->bind_param(“sss”, $nama, $jenis_kelamin, $kota);
if($insert->execute())
{
header(“location:index.php”);
}
else
{
echo “GAGAL INSERT”;
}
?>
nama file : edit.php
<?php
include_once “koneksi.php”;
$id = $_GET[‘id’];
$select = $koneksi->prepare(“SELECT nama, jenis_kelamin, kota FROM `penduduk` WHERE id=?”);
$select->bind_param(“i”, $id);
$select->execute();
$select->store_result();
$select->bind_result($db_nama, $db_kelamin, $db_kota);
$select->fetch();
?>
<form class=”ui form” action=”proses-edit.php?id=<?= $id; ?>” method=”post”>
<div class=”field”>
<label>Nama</label>
<input name=”nama” placeholder=”Nama Anda” type=”text” value=”<?= $db_nama; ?>”>
</div>
<div class=”field”>
<label>Jenis Kelamin</label>
<select class=”ui dropdown” name=”jenis_kelamin”>
<option value=””>Select</option>
<option value=”Laki – laki”>Laki – Laki</option>
<option value=”Perempuan”>Perempuan</option>
</select>
</div>
<div class=”field”>
<label>Kota</label>
<input name=”kota” placeholder=”Kota Anda” type=”text” value=”<?= $db_kota; ?>”>
</div>
<button class=”ui button blue” type=”submit”>Edit</button>
</form>
nama file : proses-edit.php
<?php
include_once “koneksi.php”;
$id = $_GET[‘id’];
$nama = $_POST[‘nama’];
$kelamin = $_POST[‘jenis_kelamin’];
$kota = $_POST[‘kota’];
$edit = $koneksi->prepare(“UPDATE `penduduk` SET `nama`=?, `jenis_kelamin`=?, `kota`=? WHERE id=?”);
$edit->bind_param(“sssi”, $nama, $kelamin, $kota, $id);
if($edit->execute())
{
header(“location:index.php”);
}
else
{
echo “GAGAL UPDATE”;
}
}
nama file : delete.php
<?php
include_once “koneksi.php”;
$id = $_GET[‘id’];
$delete = $koneksi->prepare(“DELETE FROM penduduk WHERE id=?”);
$delete->bind_param(“i”, $id);
if($delete->execute())
{
header(“location:index.php”);
}
else
{
echo “GAGAL DELETE”;
}
?>
ketika saya proses index.php di browser, outputnya :
Parse error: syntax error, unexpected 'id' (T_STRING), expecting ',' or ')' in C:\xampp\htdocs\latihan\index.php on line 24
0
1 Jawaban:
coba isi file index.php di kosongkan dulu; biar tau errornya dimana.
0