Postingan lainnya
Data yang di input tidak tersimpan ke database
mohon bantuanya, saya lagi belajar tentang CRUD, saya bingung kenapa pas input title, gambar, ringkasan dan artikel ga mau masuk kedalam database. apakah ada yang salah pada script saya.. ?
simpan.php
<?php
$server="localhost";
$username = "root";
$password = "";
$database = "dbweb";
$kon = new \mysqli($server, $username, null, $database);
if(isset($_POST['tambah'])){
$path = './images/';
$nama_g = $_FILES['gambar']['name'];
$sumber_g = $_FILES['gambar']['tmp_name'];
move_uploaded_file($sumber_g, $path.$nama_g);
$insert = mysqli_query($kon, "INSERT INTO artikel VALUES ('".$_POST['title']."', '".$nama_g."', '".$_POST['ringkasan']."', '".$_POST['blog']."')");
if($insert){
echo 'data sukses';
}else{
echo "Maaf, Terjadi kesalahan saat mencoba untuk menyimpan data ke database.";
}
}
?>
tambah.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Alaskaki.my.id</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/blog-home.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="#">Alas Kaki</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item ">
<a class="nav-link" href="index.html">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="about.html">About</a>
</li>
</ul>
</div>
</div>
</nav>
<h2>FORM TAMBAH ARTIKEL</h2>
<form action="simpan.php" method="POST" enctype="multipart/form-data">
<table>
<tr>
<td>Title </td>
<td><input type="text" name="title" placeholder="Judul" /></td>
</tr>
<tr>
<td>Gambar </td>
<td><input type="file" name="gambar"/></td>
</tr>
<tr>
<td>Ringkasan</td>
<td><textarea name="ringkasan"></textarea></td>
</tr>
<tr>
<td>Artikel</td>
<td><textarea name="blog"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="tambah" value="Tambah">
<button type="reset" value="Reset">Reset</button>
</td>
</tr>
</table>
</form>
<!-- /.container -->
<!-- Footer -->
<footer class="py-5 bg-dark">
<div class="container">
<p class="m-0 text-center text-white">Copyright © Your Website 2017</p>
</div>
<!-- /.container -->
</footer>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/popper/popper.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
mohon petunjuknya..
0
Tanggapan
kenapa data yang saya simpan di form web tidak tersimpan di database??
3 Jawaban:
Koneksi ke databse nya sudah di tes? Takutnya belum terkoneksi dengan database nya
0
tambahin mysqli_errornya gan supaya kthuan terkoneksi apa engga ke dbnya
0
kyknya koneksinya gan. Coba diganti jadi :
$kon = mysqli_connect($server, $username, $password, $database) or die(mysqli_error());
0