Buat daftar drop-down yang opsinya diambil dari database MySQL di PHP





    $con = mysqli_connect("localhost","root","","example_store");





    $sql = "SELECT * FROM `category`";

    $all_categories = mysqli_query($con,$sql);







        $name = mysqli_real_escape_string($con,$_POST['Product_name']);



        $id = mysqli_real_escape_string($con,$_POST['Category']);





        "INSERT INTO `product`(`product_name`, `category_id`)

            VALUES ('$name','$id')";








            echo '<script>alert("Product added successfully")</script>';






<!DOCTYPE html>

<html lang="en">


    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport"

          content="width=device-width, initial-scale=1.0">    



    <form method="POST">

        <label>Name of Product:</label>

        <input type="text" name="Product_name" required><br>

        <label>Select a Category</label>

        <select name="Category">





                while ($category = mysqli_fetch_array(



                <option value="<?php echo $category["Category_ID"];



                    <?php echo $category["Category_Name"];










        <input type="submit" value="submit" name="submit">





How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.