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:
I got exactly this assignment from my internship. it was horror but you helped me...thank you very much....KEEP GOING
Thank You bhai.. helpful video... great keep helping
thank you sir
Thanks a lot. Works Great
you are the best after 100 video i found this + worked perfectly
How does it use for 3 select options. Can you help me.
Thank you.
You're welcome!
Thank Sir. this is very helpful. Can I also store and display multiple values from the database ?
Yes, any numbers of values can be stored in database and then use attribute 'multiple' in select tag to select multiple options.
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...
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
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.
@@enrichinglife2103 it doesnt workk what to do please
Maybe you have a syntax error, use the console and seach if you have an error in debugger
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?
Php doesn't have onclick/ onchange functions, so it looks not possible.
How to submit in other table to store these values? Thanks help me
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.
Plz use the link to see the video ua-cam.com/video/M1F6KV-WKt4/v-deo.html
Sir how to use this in netbean while using JDBC HTML java
Sorry, i don't know about it.
your source code link does not work any more or at least not for me :(
Sorry that domain expired, please use this new link to see the source code- mysource123.blogspot.com/2021/09/file-dropdown.html
@@enrichinglife2103 thats great Thanks for your quick response :)
$val= $_GET["value"]; this line cause an Error
Pls check your code carefully.
May be in the select tag, "onchange" function not properly set to sent the value of option.
@@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"]"
bro it not working an error was displaying
I have checked. It's working, what error is showing.
Where's the source code your domain has expired
Please use the link- mysource123.blogspot.com/
@@enrichinglife2103 thanks for the link i appreciate it 🙏
can i get source code please
Path for source code i have placed in bottom of description. Pl see.