Postingan lainnya
CRUD PHP, Halaman Update/Edit Error
Gan errornya dimana?
<?php
require_once 'core/init.php';
require_once 'view/header.php';
$error = '';
$id = $_GET['id'];
if (isset($_GET['id'])) {
$article = show_id($id);
while ($row = mysqli_fetch_assoc($article)) {
$judul_awal = $row['judul'];
$konten_awal = $row['isi'];
$tag_awal = $row['tag'];
}
}
if (isset($_POST['submit'])) {
$judul = $_POST['judul'];
$konten = $_POST['konten'];
$tag = $_POST['tag'];
if (!empty(trim($judul)) && !empty(trim($konten)) ) {
if (edit_data($judul, $konten, $tag, $id)) {
header('Location: index.php');
}
else {
$error = "Ada Yang Salah";
}
}
else {
$error = "Judul & Konten Tidak Boleh Kosong";
}
}
?>
<form action="edit.php" method="post">
<label for="judul">Judul</label><br>
<input type="text" name="judul" value="<?= $judul_awal; ?>"><br>
<label for="konten">Isi</label><br>
<textarea name="konten" rows="8" cols="80"><?= $konten_awal; ?></textarea><br>
<label for="tag">Tag</label><br>
<input type="text" name="tag" value="<?= $tag_awal; ?>"><br>
<br>
<div id="error"> <?= $error; ?> </div><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
require_once 'view/footer.php';
?>
Setelah di submit jadi gini
0
7 Jawaban:
judul, konten, tag valuenya rubah kayak contoh :
if(isset($_POST["konten"])) {echo $_POST["konten"];} else {echo $konten_awal;}
0
coba gini gan
<?php
require_once 'core/init.php';
require_once 'view/header.php';
$error = $id = $konten_awal = $tag_awal = $judul_awal = '';
$id = $_GET['id'];
if (isset($_GET['id'])) {
$article = show_id($id);
while ($row = mysqli_fetch_assoc($article)) {
$judul_awal = $row['judul'];
$konten_awal = $row['isi'];
$tag_awal = $row['tag'];
}
}
if (isset($_POST['submit'])) {
$judul = $_POST['judul'];
$konten = $_POST['konten'];
$tag = $_POST['tag'];
if (!empty(trim($judul)) && !empty(trim($konten))) {
if (edit_data($judul, $konten, $tag, $id)) {
header('Location: index.php');
}
else {
$error = "Ada Yang Salah";
}
}
else {
$error = "Judul & Konten Tidak Boleh Kosong";
}
}
?>
<form action="edit.php" method="post">
<label for="judul">Judul</label><br>
<input type="text" name="judul" value="<?= $judul_awal; ?>"><br>
<label for="konten">Isi</label><br>
<textarea name="konten" rows="8" cols="80"><?= $konten_awal; ?></textarea><br>
<label for="tag">Tag</label><br>
<input type="text" name="tag" value="<?= $tag_awal; ?>"><br>
<br>
<div id="error"> <?= $error; ?> </div><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
require_once 'view/footer.php';
?>
0
<?= $judul_awal; ?> diganti <?=$judul_awal?>
krna singkatan php setelah = tidak boleh ada spasi
0
<?= $judul_awal; ?> diganti <?=$judul_awal?>
<?php
require_once 'core/init.php';
require_once 'view/header.php';
$error = '';
$id = $_GET['id'];
if (isset($_GET['id'])) {
$article = show_id($id);
while ($row = mysqli_fetch_assoc($article)) {
$judul_awal = $row['judul'];
$konten_awal = $row['isi'];
$tag_awal = $row['tag'];
}
}
if (isset($_POST['submit'])) {
$judul = $_POST['judul'];
$konten = $_POST['konten'];
$tag = $_POST['tag'];
if (!empty(trim($judul)) && !empty(trim($konten)) ) {
if (edit_data($judul, $konten, $tag, $id)) {
header('Location: index.php');
}
else {
$error = "Ada Yang Salah";
}
}
else {
$error = "Judul & Konten Tidak Boleh Kosong";
}
}else{
$judul_awal='';
$konten_awal='';
$tag_awal='';
$error='';
}
?>
<form action="edit.php" method="post">
<label for="judul">Judul</label><br>
<input type="text" name="judul" value="<?= $judul_awal; ?>"><br>
<label for="konten">Isi</label><br>
<textarea name="konten" rows="8" cols="80"><?= $konten_awal; ?></textarea><br>
<label for="tag">Tag</label><br>
<input type="text" name="tag" value="<?= $tag_awal; ?>"><br>
<br>
<div id="error"> <?= $error; ?> </div><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
require_once 'view/footer.php';
?>
0
alo @alfarisi untuk error yg kamu hadapi coba perhatikan bagian form pada bagian attribut action nya menandakan submit form ke 'edit.php'
Dan apakah kode di atas dari file edit.php atau file lain untuk di post ke edit.php ??
- jika betul dari edit.php, maka form action nya harus di tambahan get id nya. menjadi edit.php&id=id atau menambahkan input hidden id di form kamu.
semoga aja bisa membantu ya..:)
0
kasih di atas sendiri
error_reporting(0);
0