简体   繁体   中英

Insert database multi-part/form-data not working (data not stored)

I'm a newbie on php. I try this form but, it won't store data from input to database. Page reloaded but insert data still not work. here's the connection

<?php $connection = new mysqli("localhost","root","","geminpo"); ?>

here's the form

<form method="POST" enctype="multipart/form-data">
    <input type="text" name="judul">
    <button name="save">simpan</button>
</form>

here's the php

<?php 
    if (isset($_POST['save'])) {
        $connection->query("INSERT INTO artikel(judul)VALUES('$_POST[judul]')");
    }
 ?>

Button name is not submitted with the form then $_POST['save'] is not set.
I suggest to use a hidden input :

<input type="hidden" name="save" />

Try this, you were missing the ' when accessing the post array value:

 <?php 
    if (isset($_POST['save'])) {
        $connection->query("INSERT INTO artikel (judul) VALUES ('" . $_POST['judul'] . "')");
    }
 ?>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM