2 Replies - 982 Views - Last Post: 25 August 2012 - 05:40 AM Rate Topic: -----

#1 Lydon  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 87
  • Joined: 22-May 08

SHOW TABLES in drop down menu

Posted 25 August 2012 - 03:31 AM

Hi all

I'm working on a form where I need to see table names from a database.
The form currently shows these table names in a drop down menu just as I want...
<select name="windfarm_name"> 
<?php
  require 'db_connect_windfarms.php';
  $result = mysql_query("SELECT table_name FROM INFORMATION_SCHEMA.TABLES
  WHERE table_schema = 'dave_windfarms'") or die(mysql_error());
			  
while($array=mysql_fetch_row($result))
  { 
	echo "<option value=" . $array[0] . ">" . $array[0] . "</option>"; 
  }
?> 
</select>



Question is, when the form is submitted, how do I get hold of what was selected into a variable?
For example...
$table = $_POST['what_goes_here?'];



How do I get whatever was selected out of the array into a variable to use later on?

Thanks in advance for any help/advice.

Is This A Good Question/Topic? 0
  • +

Replies To: SHOW TABLES in drop down menu

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 948
  • View blog
  • Posts: 2,357
  • Joined: 15-February 11

Re: SHOW TABLES in drop down menu

Posted 25 August 2012 - 05:40 AM

Since windfarm_name is the name of your SELECT element then it'll be either
$table = $_POST['windfarm_name'];
//OR
$table = $_GET['windfarm_name'];

depending on what method you used to submit the form.

This post has been edited by codeprada: 25 August 2012 - 05:40 AM

Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,887
  • Joined: 08-August 08

Re: SHOW TABLES in drop down menu

Posted 25 August 2012 - 05:40 AM

First, arrays ARE variables so there's no need to copy from one to another. This is a waste of time and effort and it just makes you look like a noob:
$x = $_POST['x'];

Second, you don't show the form so we don't know if it uses post or get as its method.
Third, mysql_* functions are deprecated. Learn prepared statements (PDO or MySQLi).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1