Jump to content

Dropdown list with db tables and files


logintech

Recommended Posts

Hello everyone

 

I have two dropdown lists. First one you can see the tables of my db and the second one the files inside a folder. The problem is that i can't send my selections from the dropdown list to an other file.

My project is to choose a table, then a CSV file and then load the file in db.

 

index.php:

<?php //EMFANISH PINAKWN
include("../forma/dbCon.php");

echo "<form action='load_table_test.php' method='POST'>";
	$sql="SHOW TABLES FROM misthodosia";
	$result=mysql_query($sql);

	if (!$result) {
		echo "Υπάρχει πρόβλημα με την βάση\n";
		echo 'MySQL Error: ' . mysql_error();
		exit;
	}

	echo"<select>";
		while ($row = mysql_fetch_row($result)) {
			echo "<option name='{row[0]}' value='{row[0]}'>{$row[0]}</option>";
		}
	echo"</select>";
	mysql_free_result($result);

//==========================EMFANISH ARXEIWN==========================

function populateDropdown(){
	$path = glob("C:\\xampp\\htdocs\\dbadmin\\upload_files\\*"); //the double \\ is not a typo you

	//have to escape it
	//if the path cannot be found
	if(!($path)){
		echo("Δεν υπάρχει ο φάκελος");
		return;
	}//if

	//the path is valid
	else{
		foreach($path as $k){
		$i = basename($k);

		echo "<option name='$i'>".$i."</option>";

		}//foreach
	}//else
}//populateDropdown






echo"<select>";
	populateDropdown();
echo"</select> ";


echo"<input type='submit' name='submit' value='Φόρτωσε1111111' />";
echo "</form>";


$hello="hello";

?>

 

 

load_table_test.php:

<?php
include("../forma/dbCon.php");



echo $_POST['hello'];

echo $_POST['{row[0]}'];
echo $i;


//$pinakas=$_POST['pinakas']
//$arxeio=$_POST['arxeio']

//$pinakas=$_POST['row']
//$arxeio=$_POST['diadromi']


//mysql_query("LOAD DATA LOCAL INFILE "$arxeio" INTO TABLE $pinakas
//FIELDS
//TERMINATED BY ','
//ENCLOSED BY '\"'
//LINES TERMINATED BY '\n')



echo "$arxeio";
echo "$pinakas";



    
echo "<br/><br/><br/><br/><br/><a href='index.php'>Επιστροφή στην προηγούμενη σελίδα.</a>";                                     

?>

 

 

errors:

Notice: Undefined index: hello in C:\xampp\htdocs\dbadmin\load_table_test.php on line 6

Notice: Undefined index: {row[0]} in C:\xampp\htdocs\dbadmin\load_table_test.php on line 8

Notice: Undefined variable: i in C:\xampp\htdocs\dbadmin\load_table_test.php on line 9

Notice: Undefined variable: arxeio in C:\xampp\htdocs\dbadmin\load_table_test.php on line 27

Notice: Undefined variable: pinakas in C:\xampp\htdocs\dbadmin\load_table_test.php on line 28

Link to comment
Share on other sites

when refferencing drop down lists from a form into a variable you would do it by pointing to the name of the select element, not the option.  An attempt to make this clearer:

 

$_POST['textbox1'] => 'hello'

would come from a form field like so:

<input type="text" name="textbox1" value ="hello" >

 

$_POST['dropdown1'] => 'second Option'

would come from a drpdown field like so:

<select name="dropdown1">

  <option value="First Option">1st Option</option>

  <option value="Second Option" selected="selected">2nd Option</option>

</select>

 

Hope that helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.