I want to use the html select to search for info from the database but no matter how I tried, it doesn’t work. So, i thought maybe since there is no way I was able to detect which element or data was selected(maybe that is why it dosen’t pull anything from the database).
My question now is how am I able to detect which select statement was selected(I populate the select field dynamically from the database). This is the code I write myself.
I don’t think you can do what you’re hoping to do by specifying the same parameter name twice in the query. I believe you have to name them separately, then pass the same value into both.
<?php
/* DEVELOPMENT TROUBLESHOOTING ONLY !!! */
error_reporting(-1);
ini_set('display_errors', 1);
/* END OF TROUBLESHOOTING LINES */
if($_SERVER['REQUEST_METHOD'] == 'POST'){
You didn’t give the <select> “multiple” which would allow more than one <option> to be selected and be an array not a string. AFAIK, without multiple, only one option can be selected. Your code is currently giving every option selected. I don’t know if any given browser would take one and disregard the others or pass an array of values. As you want only one option, for now try removing the selected="selected" bit.
You also call closeCursor() before you fetch the results - won’t this give you no results? Surely the closeCursor() comes after you’ve retrieved the results?
This is the error it shows for using display_errors()
Fatal error: Uncaught Error: Call to undefined function display_errors() in C:\xampp\htdocs\pakistani\bred.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\pakistani\bred.php on line 3
Show us the code as it is now. Have you fixed all the errors pointed out above, such as those where you just put quoted strings in place without echo statements?
Where does your database connection come from? I see you using $conn, but I don’t see where you either define it, or include a file that defines it for you.