Selamat malam agan2 semuanya,
ane newbi butuh bantuan agan2 nih...
Ane bikin script buat update data dari database posgreSQL gan tapi ini scrip error mulu Gan.
Berikut ane lampirkan potongan2 script nya gan.
berikuk script viewtable.php nya Gan,
Quote:
<?php
include ("koneksi.php");
$data = pg_query("select * from perguruantinggi");
?>
<html>
<head>
<title>Data Perguruan Tinggi Kota Padang</title>
<link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<button style="margin-left:5%">Print Document</button>
[removed]
function printd(){
window.open("print.php","_blank");
}
[removed]
<h1><center>Data Perguruan Tinggi Kota Padang</h1>
<table border="1" width="90%" style="border-collapse:collapse;" align="center">
<tr class="tableheader">
<th rowspan="1">GID</th>
<th>Perguruan Tinggi</th>
<th>Alamat</th>
<th>No Telfon</th>
<th>email</th>
<th>Website</th>
<td>Opsi</td>
</tr>
<?php
$i=1;
while($hasil = pg_fetch_array($data)){ ?>
<tr id="rowHover">
<td width="5%" align="center"><?php echo $i; ?></td>
<td width="30%" id="column_padding"><?php echo $hasil['nama']; ?></td>
<td width="30%" id="column_padding"><?php echo $hasil['alamat']; ?></td>
<td width="20%" id="column_padding"><?php echo $hasil['no_telfon']; ?></td>
<td width="5%" id="column_padding"><?php echo $hasil['email']; ?></td>
<td width="5%" id="column_padding"><?php echo $hasil['website']; ?></td>
<td>
<a href="edit.php?id=<?php echo $hasil['gid']; ?>">Edit</a> ||
<a href="delete.php?id=<?php echo $hasil['gid']; ?>">Hapus</a>
</td>
</tr>
<?php $i++;} ?>
</table>
<br />
</body>
</html>
gambar view tabelnya
Script untuk form editnya gan :
Quote:
<html>
<?php
include('koneksi.php');
?>
<head>
<title>Form Edit</title>
</head>
<body>
<h1>Form Ubah Data</h1>
<?php
$id = $_GET['id'];
$query = pg_query("select * from perguruantinggi where gid='$id'") or die(pg_last_error());
$hasil = pg_fetch_array($query);
?>
<form name="updatedata" action="update.php" method="post">
<input type="hidden" name="gid" value="<?php echo $id; ?>" />
<table border="0" cellpadding="5" cellspacing="0">
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td>Nama</td>
<td>:</td>
<td><input type="text" name="nama" align="LEFT" required="required" size="50" value="<?php echo $hasil['nama']; ?>" /></td>
</tr>
<tr>
<td>Alamat</td>
<td>:</td>
<td><input type="text" name="alamat" align="LEFT" required="required" size="50" value="<?php echo $hasil['alamat']; ?>" /></td>
</tr>
<tr>
<td>No Telfon</td>
<td>:</td>
<td><input type="text" name="no_telfon" align="LEFT" required="required" size="50" value="<?php echo $hasil['no_telfon']; ?>" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type="email" name="email" align="LEFT" required="required" size="50" value="<?php echo $hasil['email']; ?>" /></td>
</tr>
<tr>
<td>Website</td>
<td>:</td>
<td><input type="text" name="website" align="LEFT" required="required" size="50" value="<?php echo $hasil['website']; ?>" /></td>
</tr>
<tr>
<td>Longitude</td>
<td>:</td>
<td><input type="text" name="longitude" align="LEFT" required="required" size="50" value="<?php echo $hasil['longitude']; ?>" /></td>
</tr>
<tr>
<td>Latitude</td>
<td>:</td>
<td><input type="text" name="latitude" required="required" size="50" value="<?php echo $hasil['latitude']; ?>" /></td>
</tr>
<tr>
<td align="right" colspan="3"><input type="submit" name="submit" value="Simpan" size="50" value="" /></td>
</tr>
</tbody>
</table>
</form>
<a href="viewtable.php">Lihat Data</a> || <a href="logout.php">Logout</a>
</body>
</html>
berikut script actionnya ane kasih nama update.php
Quote:
<?php
include('koneksi.php');
$id = pg_escape_string ($_POST['gid']);
$nama = pg_escape_string ($_POST['nama']);
$alamat = pg_escape_string ($_POST['alamat']);
$no_telfon = pg_escape_string ($_POST['no_telfon']);
$email = pg_escape_string ($_POST['email']);
$website = pg_escape_string ($_POST['website']);
$longitude = pg_escape_string ($_POST['longitude']);
$latitude = pg_escape_string ($_POST['latitude']);
$query = "UPDATE perguruantinggi SET nama='$nama', alamat='$alamat', no_telfon='$no_telfon', email='$email', website='$website', longitude='$longitude', latitude='$latitude', WHERE gid='$id'";
$result = pg_query($query);
if ($result) {
header('location:viewtable.php?message=success');
}
?>
setelah di-run.
error setelah klik tombol simpan
Mohon batuannya agan2 , mastah2 smuanya. buat ngatasin error pada update datanya