-1

this is my form. in heere i want to input data select option in while loop

<form method="post" action="process/input_penilaian_produk.php">
            <div class="input">
                <p>Produk</p>
<?php  
    $q="SELECT * FROM `produk`";
    $qe=mysqli_query($koneksi,$q);
    while ($de=mysqli_fetch_array($qe)) {
        $id_produk=$de['id_produk'];
        $nama_produk=$de['nama_produk'];
        echo "
                <select name=\"id_produk\">
                    <option value=\"".$id_produk."\">".$nama_produk."</option>
                </select>
        ";
    }
?>          

<?php 
    $q="SELECT * FROM `kriteria`";
    $qe=mysqli_query($koneksi, $q);
    while ($de=mysqli_fetch_array($qe)) {
        $id_kriteria=$de['id'];
        $nama_kriteria=$de['nama_kriteria'];
        echo "
                    <p>".$nama_kriteria."</p>
                    <select name=\"id_penilaian\">
        ";

        $q1="SELECT * FROM `penilaian_kriteria` WHERE `id_kriteria`=\"".$de['id']."\"";
        $qe1=mysqli_query($koneksi, $q1);
        while ($de1=mysqli_fetch_array($qe1)) {
            $id_penilaian=$de['id_penilaian'];
            $id_kriteria=$de1['id_kriteria'];
            $penilaian=$de1['penilaian'];
            $bobot=$de['bobot'];
            echo "
                        <option value=\"".$id_penilaian."\">".$penilaian."</option>
            ";

        }
                    echo "
                        </select>
                    ";

    }
?>                              
                <input class="btn_input" type="submit" value="input">
            </div>
        </form>

here's my code to insert. this is the code to insert the data. what makes me confusing is, how can i insert same is into different table data

<?php  
    include("koneksi.php");

    $id_produk=$_POST['id_produk'];
    $id_penilaian=$_POST['id_penilaian'];

    $q="INSERT INTO `penilaian_produk` VALUES('','$id_produk','$id_produk','','','','')";
    $qe=mysqli_query($koneksi, $q);
    if ($qe) {
        header('location:../produk.php');
    } else{
        echo "gagal";
    }
?>

i've been try this code and it works, no error. but when i check phpmysql, the data is empty. i don't know what to do to solve this problem how can i insert loop while $id_penilaian into database?

how can i insert differnt id_penilaian into database in the same query? please help me to solve this problem. Thank you

chemy
  • 1
  • 3
  • 3
    **Warning:** You are wide open to [SQL Injections](http://php.net/manual/en/security.database.sql-injection.php) and should really use parameterized [Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead of manually building your queries like that. Specially since you're not escaping the user inputs at all! – Dharman Jan 06 '19 at 17:26
  • [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – Dharman Jan 06 '19 at 17:29
  • 3
    *"no error"* - That's because you didn't use error reporting *and* `mysqli_error($koneksi)` on the query. – Funk Forty Niner Jan 06 '19 at 17:38
  • You probably should move the ` – user3783243 Jan 06 '19 at 17:56

1 Answers1

0

For the line,

$q="INSERT INTO penilaian_produk VALUES('','$id_produk','$id_produk','','','','')";

check into the database, that what kind of constraints you have applied on each column and also check the corresponding column datatypes, that you have used during table creation.

Might be this will be the problem here.

deepakbhavale67
  • 347
  • 5
  • 13