saat di isi lalu pencet post , selalu muncul input gagal, bagaimana biar berhasil

form.php

<!DOCTYPE html>
<html lang="id" dir="ltr">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Tulis Pesan</title>
	<style type="text/css">
			* {
				list-style: none;
				text-decoration: none;
			}
			body {
				margin: 0;
				background: url(paper.jpg);
				background-size: cover;
				background-attachment: fixed;
			}
			.header {
				background: lightgray;
				border-bottom :7px solid gray;
				border-radius: 0 0 10px 10px;
			}
			.header ul {
				margin: 0;
				padding: 0;
				text-align: center;

			}
			.header ul li h1 {
				margin: 0;
				padding: 0;
				font-size: 10mm;
			}
			.button1 {
				border-radius: 0px 5px  5px 0px ;
				background: lightgray;
				border: 2px solid black;
				border-left: lightgray;
				transition: 1s;
				box-shadow: 10px white;
			}
			.button1:hover {
				border-radius: 0px 5px  5px 0px ;
				background: black;
				border: 2px solid gray;
			  padding: 5px 15px;
				border-left: black;
				box-shadow: 10px white;
			}
			.button1 a {
				color: black;
			}
			.button1 a:hover {
				color: white;
			}
			.form {
				position: fixed;
				margin: 101.5px 25%;
				width: 50%;
				background: rgba(0, 0, 0, 0.5);
				padding: 0;
			}
			.form form input {
				border-radius:
			}
			.btn {
				margin: 10px;
				right: 0;
				border:1.5px solid black;
				background-color: gray;
				color: white;
				opacity: 40%;
				transition: 2s;
			}
		    .btn:hover {
				margin: 10px;
				right: 0;
				border:1.5px solid black;
				background-color: gray;
				color: white;
				opacity: 100%;
			}
	</style>
</head>
<body>
	<div class="header">
		<button class="button1" style="left: 0;"><a href="Pesanku.php">Back</a></button>
		<br>
		<ul>
			<li><h1>Pesanku</h1></li>
			<br>
		</ul>
        <br>
	</div>
	<div class="form">
		<form method="Post" action="koneksidatabase.php">

			<center>
				<br>
				<input type="text" name="for" placeholder="Untuk..." required>
			<br><br>
			<input type="text" name="pesan" placeholder="Pesan...." required>
			<br><br>
			<input type="submit" value="Post" name="sub">
 			<br><br>
			</center>

		</form>

	</div>
</body>
</html>

koneksi.php

<?php
$conn = mysqli_connect("localhost","root","","pesankupost1");

// Check connection
if (mysqli_connect_errno()){
	echo "Koneksi database gagal : " . mysqli_connect_error();
}

?>

koneksidatabase.php

<?php
include "koneksi.php";
    if ($_POST["sub"]) {
  $for  = $_POST['for'];
  $pesan  = $_POST['pesan'];
  $mysqli  = "INSERT INTO post ('For', 'Pesan') VALUES ('$for', '$pesan')";

  mysqli_query($conn, $mysqli);
  if (  mysqli_query($conn, $mysqli)) {
    echo "Input berhasil";
  } else {
    echo "Input Gagal!";
  }
  mysqli_close($conn);
} ?>
avatar Ahdavi
@Ahdavi

2 Kontribusi 0 Poin

Diperbarui 4 tahun yang lalu

1 Jawaban:

<div>1. Coba cek lagi, nama kolomnya pake huruf kecil semua atau emang pake huruf Kapital dulu baru huruf kecil.<br>2. Gunakan isset untuk pengecekan bahwa user telah klik tombol sumbit<br>3. Hapus salah satu dari script mysqli_query<br><br>Contohnya sebagai berikut :</div><pre>&lt;?php include "koneksi.php"; if (isset($_POST["sub"])) { $for = $_POST['for']; $pesan = $_POST['pesan']; $mysqli = "INSERT INTO post ('for', 'pesan') VALUES ('$for', '$pesan')";

$insert = mysqli_query($conn, $mysqli); if ( $insert ) { echo "Input berhasil"; } else { echo "Input Gagal!"; } mysqli_close($conn); } ?&gt;</pre><div><br></div>

avatar ahanafi
@ahanafi

815 Kontribusi 554 Poin

Dipost 4 tahun yang lalu

Tanggapan

Sudah saya cek tapi tetep tidak terinput di database

Coba koneksi dbnya dah bener belum. Coba test syntax sql di phpmyadmin. Bener kata kaka Ahdav besar kecilnya huruf diperhatikan hehe

Login untuk ikut Jawaban