php - Show a specific MySQL row based on dropdown selection -


I have created a form that includes a dropdown field

  & lt; Select Name = "Location Selection" Id = "Location Selection" tabindex = "7" & gt; & Lt; Option value = "location1" & gt; Location 1 & lt; / Options & gt; & Lt; Option value = "position 2" & gt; Location 2 & lt; / Options & gt; & Lt; Option value = "position 3" & gt; Location 3 & lt; / Options & gt; & Lt; Option value = "position 4" & gt; Location 4 & lt; / Options & gt; & Lt; / Select & gt;  

On submissions I want to draw the selected location from the dropdown and want to print a specific line from my MySQL database which will show them the address. So if they select the location 1, then it will be shown:

  Company name 1234 ABC Street New York, NY 12345  

But if they are in place 2 If you select:

  Other Company 5678 XYZ Street San Francisco, CA 12345  

And so on for 99 different locations

Here I was missing out on a variable which was started with but defined the array $ fulladdress - I'm new to MySQL so I also get it Not sure what to be kept after the selection? Is there a line number or can I enter the content of the first column or what type of ID?

Switch ($ _GET ['locationselect']) {case 'Location1': mysql_query (select from "Choose from ____ locations"); break; Case 'Location 2': mysql_query ("Choose from ____ with location"); break; } ($ Line = mysql_fetch_array ($ fulladdress)) {echo ($ line ['place_name']. "Office Building
" $ line ['address']. " . $ Line ['City']. ", Ca." $ line ['zip']. "& Lt; br & gt; & lt; br & gt;"); }

Any help to solve this problem would be greatly appreciated. I know my code is messy, but I hope you can think of what I'm trying to do.

Thank you!

I'm not sure about using the case statement, what you can do is a parameterized query Then it will be:

  mysql_query ("Choose full address from location where location = '". $ Location. "' ');  

Using the dropdown value, you can pass it in the $ location variable. But if you are showing so much value in the search box you might want to look like something. Definitely after you avoid the input.

Edit:

The above method is not very secure, you should actually use the MySkeli and use something like ready statements: / P>

  $ stmt = $ dbConnection-> Prepare ('Select location from WHERE name =?'); $ Stmt-> gt; Bind_param ('s', $ name);  

Check this post for more information


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -