to the point.
mysqli prepared statement does not submitting data into database, and mysqli_error
not returning any errors
might be because I made a mistake writing the error handler because it shows the message when mysqli_stmt_execute
does not returns TRUE
EDIT
it looks like mysqli_stmt_execute()
does not executes the query. why is that?
PHP-mysqli script :
// Simpan data ke dalam variable
$nama_produk=$_POST['nama_produk'];
$id_kategori=$_POST['kategori'];
$id_kategori2=$_POST['kategori2'];
$label=$_POST['label'];
$harga=$_POST['harga'];
$harga2=$_POST['harga2'];
$stok=$_POST['stok'];
$deskripsi=$_POST['deskripsi'];
$spesifikasi=$_POST['spesifikasi'];
$potongan=$_POST['potongan'];
$produk_seo = seo_title($_POST['nama_produk']);
$tanggal=$tgl_sekarang;
$gambar=$nama_file_unik;
$stmt=mysqli_prepare($con,"INSERT INTO produk(nama_produk,produk_seo,id_kategori,id_kategori2,label,harga,harga2,stok,spesifikasi,deskripsi,tgl_masuk,potongan,gambar) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)");
mysqli_stmt_bind_param($stmt,"sssssssssssss",$nama_produk,$produk_seo,$id_kategori,$id_kategori2,$label,$harga,$harga2,$stok,$spesifikasi,$deskripsi,$tanggal,$potongan,$gambar);
if(mysqli_stmt_execute($stmt)){
mysqli_stmt_error($stmt);
} else {
echo"<h1>Query gagal</h1>";
mysqli_error($con);
mysqli_errno($con);
mysqli_stmt_error($stmt);
}
usually there is a message saying the the number of something does match something etc but there is none of that, just a big 'Query gagal'
Try this:
// Simpan data ke dalam variable
$nama_produk=$_POST['nama_produk'];
$id_kategori=$_POST['kategori'];
$id_kategori2=$_POST['kategori2'];
$label=$_POST['label'];
$harga=$_POST['harga'];
$harga2=$_POST['harga2'];
$stok=$_POST['stok'];
$deskripsi=$_POST['deskripsi'];
$spesifikasi=$_POST['spesifikasi'];
$potongan=$_POST['potongan'];
$produk_seo = seo_title($_POST['nama_produk']);
$tanggal=$tgl_sekarang;
$gambar=$nama_file_unik;
$stmt=mysqli_prepare($con,"INSERT INTO produk(nama_produk,produk_seo,id_kategori,id_kategori2,label,harga,harga2,stok,spesifikasi,deskripsi,tgl_masuk,potongan,gambar) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)");
if(false===$stmt){
die('Error with prepare: ') . htmlspecialchars($mysqli->error));
}
$bp = mysqli_stmt_bind_param($stmt,"sssssssssssss",$nama_produk,$produk_seo,$id_kategori,$id_kategori2,$label,$harga,$harga2,$stok,$spesifikasi,$deskripsi,$tanggal,$potongan,$gambar);
if(false===$bp){
die('Error with bind_param: ') . htmlspecialchars($stmt->error));
}
$bp = $stmt->execute();
if ( false===$bp ) {
die('Error with execute: ' . htmlspecialchars($stmt->error));
}
$stmt->close();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.