How to get / populate select option values from database using PHP

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • How to populate HTML select options from the values fetched from database using the PHP code is explained with example. Create Select drop down menu with values taken from database. I have used html, ajax, php & sql codes.
    For create database "drinks" with table "list" run the following code in database SQL.
    CREATE DATABASE drinks;
    CREATE TABLE list (
    id INT(2) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    D_Type VARCHAR(10) NOT NULL,
    D_Name VARCHAR(10) NOT NULL
    );
    INSERT INTO list (id, D_Type, D_Name) VALUES ('', 'Cold', 'Apple Juce');
    INSERT INTO list (id, D_Type, D_Name) VALUES ('', 'Hot', 'Coffee');
    INSERT INTO list (id, D_Type, D_Name) VALUES ('', 'Cold', 'Kiwi Juce');
    INSERT INTO list (id, D_Type, D_Name) VALUES ('', 'Hot', 'Tea');
    Source code path:

КОМЕНТАРІ • 35

  • @hedrobc8714
    @hedrobc8714 Рік тому

    I got exactly this assignment from my internship. it was horror but you helped me...thank you very much....KEEP GOING

  • @someshwarghorpade5043
    @someshwarghorpade5043 3 роки тому

    Thank You bhai.. helpful video... great keep helping

  • @JimPaoloCinco-iy4zv8kf3o
    @JimPaoloCinco-iy4zv8kf3o Рік тому

    thank you sir

  • @rameshmadara1
    @rameshmadara1 Рік тому

    Thanks a lot. Works Great

  • @minasseracnr5953
    @minasseracnr5953 3 роки тому

    you are the best after 100 video i found this + worked perfectly

  • @chiranthaekanayake7186
    @chiranthaekanayake7186 2 роки тому +1

    How does it use for 3 select options. Can you help me.

  • @nelsonviernes5119
    @nelsonviernes5119 2 роки тому

    Thank you.

  • @ahmedabdiguure4386
    @ahmedabdiguure4386 3 роки тому

    Thank Sir. this is very helpful. Can I also store and display multiple values from the database ?

    • @enrichinglife2103
      @enrichinglife2103  3 роки тому +1

      Yes, any numbers of values can be stored in database and then use attribute 'multiple' in select tag to select multiple options.

  • @poojabharti7502
    @poojabharti7502 3 роки тому

    Pls make video for select drop-down list using Ajax without JSON or jQuery and pls make video for database. if I wants to add value for select drop-down without select query...

  • @jonellecorridon4330
    @jonellecorridon4330 3 роки тому

    Hi, do you know what could cause an error for this line $val = $_GET["value"]; in the php file?
    I got this error.
    Warning: Undefined array key "value" in C:\xampp\htdocs\...\helper.php on line 8
    Select Drink

    • @enrichinglife2103
      @enrichinglife2103  3 роки тому

      Here we have not using any array, so such a error??. First to check the Ajax script is working properly and it sending selected value, plz put echo the $val. It must echo select value in html page itself.

    • @B_Y_T_E
      @B_Y_T_E 2 роки тому

      @@enrichinglife2103 it doesnt workk what to do please

    • @deborahmosqueda8103
      @deborahmosqueda8103 2 роки тому

      Maybe you have a syntax error, use the console and seach if you have an error in debugger

  • @putinninovacuna8976
    @putinninovacuna8976 4 роки тому

    I dont want using ajax or jquery i dont like javascript but php only how to get the selected value using php, can I just switch case?

    • @enrichinglife2103
      @enrichinglife2103  4 роки тому +1

      Php doesn't have onclick/ onchange functions, so it looks not possible.

  • @FreeTutorials92
    @FreeTutorials92 3 роки тому

    How to submit in other table to store these values? Thanks help me

    • @enrichinglife2103
      @enrichinglife2103  3 роки тому

      You can use javascript to display the value of second drop menu in table or input field easily. In 2-3 days, i will upload video showing that. Tx.

    • @enrichinglife2103
      @enrichinglife2103  3 роки тому

      Plz use the link to see the video ua-cam.com/video/M1F6KV-WKt4/v-deo.html

  • @vaibhavgaikwad8747
    @vaibhavgaikwad8747 2 роки тому

    Sir how to use this in netbean while using JDBC HTML java

  • @JasonPurkiss
    @JasonPurkiss 2 роки тому

    your source code link does not work any more or at least not for me :(

    • @enrichinglife2103
      @enrichinglife2103  2 роки тому +1

      Sorry that domain expired, please use this new link to see the source code- mysource123.blogspot.com/2021/09/file-dropdown.html

    • @JasonPurkiss
      @JasonPurkiss 2 роки тому

      @@enrichinglife2103 thats great Thanks for your quick response :)

  • @LeonardoGrinn
    @LeonardoGrinn 10 місяців тому

    $val= $_GET["value"]; this line cause an Error

    • @enrichinglife2103
      @enrichinglife2103  10 місяців тому

      Pls check your code carefully.
      May be in the select tag, "onchange" function not properly set to sent the value of option.

    • @LeonardoGrinn
      @LeonardoGrinn 10 місяців тому

      @@enrichinglife2103 I triple check the function works a return the value but the error is on the php file it's shows "Undefined array key "value" " with this line "$val= $_GET["value"]"

  • @saitejateja2019
    @saitejateja2019 3 роки тому

    bro it not working an error was displaying

  • @afretoon
    @afretoon 3 роки тому

    Where's the source code your domain has expired

    • @enrichinglife2103
      @enrichinglife2103  3 роки тому +1

      Please use the link- mysource123.blogspot.com/

    • @afretoon
      @afretoon 3 роки тому

      @@enrichinglife2103 thanks for the link i appreciate it 🙏

  • @indrasoni8862
    @indrasoni8862 4 роки тому

    can i get source code please

    • @enrichinglife2103
      @enrichinglife2103  4 роки тому

      Path for source code i have placed in bottom of description. Pl see.