Jump to content

[SOLVED] Problems Submitting Variables


PHPNewbie55

Recommended Posts

I am trying to create a script that imports a CSV File and allows me to Map the data to the MySQL Database.

 

First I have a form that allows me to input what CSV file and the MySQL Database and TableName to import the records into..

Then when you click "submit" the script pulls the column names from the CSV File AND the MySQL Table, and allows me to match up what CSV Column gets imported into what MySQL Column.

 

This is where I run into problems...

Since I am pulling the info from both the CSV File and the MySQL Databases..  I don't have any preset column names..

so how would I pass on each MATCH to the IMPORT portion of the script...??

 

Here is the code for the MATCHING UP page.... - Just cut and pasted so the "endings and beginnings" are not accurate

<?php
} elseif ($action == "submit") {
//   require("settings.php");
$mysqlserver == ($_POST["mysqlserver"]);
$mysqllogin ==  ($_POST["mysqllogin"]);
$mysqlpassword == ($_POST["mysqlpassword"]);
$mysqldb == ($_POST["mysqldb"]);
$mysqltbl == ($_POST["mysqltbl"]);
$csvfile == ($_POST["CSV_File"]);
$CSV_File = htmlspecialchars($csvfile);
// MAKE CONNECTION
$conn  = mysql_connect("$mysqlserver", "$mysqllogin", "$mysqlpassword");

// IF CONNECTION CANNOT BE MADE QUIT AND GIVE AN ERROR MESSAGE
if (!$conn)
  {
  die('<h4>Could <u>Not</u> Connect To The Database</h4><hr>' . mysql_error());
  }
  
mysql_select_db("$mysqldb", $conn);

######  GET CSV COLUMN NAMES
#################################################################################
$feed = fopen($CSV_File, 'r');  
$csv = file($CSV_File);

$columns = explode(",", $csv[0]);
$csv_column_names = implode("<br>", $columns);
$options = "";
//$options .= "<select name=\"select\"><option value=\"\"></option>";
foreach ($columns as $value){
$options .= "<option value=\"$value\">$value</option>"; }
//$options .= "</select>";

print "
<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" >
  <tr>
    <td><b>Match Up The MySQL Columns With The CSV Columns</b></td>
  </tr><form method=\"post\" action=\"import_csv.php?action=import\">
  <input type=\"hidden\" name=\"mysqlserver\" value=\"$mysqlserver\"/>
  <input type=\"hidden\" name=\"mysqllogin\" value=\"$mysqllogin\"/>
  <input type=\"hidden\" name=\"mysqlpassword\" value=\"$mysqlpassword\"/>
  <input type=\"hidden\" name=\"mysqldb\" value=\"$mysqldb\"/>
  <input type=\"hidden\" name=\"mysqltbl\" value=\"$mysqltbl\"/>
  <input type=\"hidden\" name=\"CSV_File\" value=\"$CSV_File\"/>
  ";

######  GET MYSQL COLUMN NAMES
#################################################################################
$mysql_column_names = "";
$get_columns = mysql_query("SELECT * FROM $mysqltbl");
while($mysql_columns = mysql_fetch_field($get_columns)) {

print "<tr>
    <td>
<div style=\"padding:5px; border-bottom:1px solid #cccccc;\">
 CSV Column: <select name=\"".$mysql_columns->name."\"><option value=\"\"></option>$options</select> Should Be Inserted Into <b>".$mysql_columns->name."</b><br>
</div>
</td>
  </tr>";


}
print "<tr><td><center><input type=\"submit\" value=\"submit\" /></center></td></tr></table></form>";
?>

 

 

This is the next page..  the IMPORT PROCESS...

<?php
} elseif ($action == "import") {
$mysqlserver == ($_POST["mysqlserver"]);
$mysqllogin ==  ($_POST["mysqllogin"]);
$mysqlpassword == ($_POST["mysqlpassword"]);
$mysqldb == ($_POST["mysqldb"]);
$mysqltbl == ($_POST["mysqltbl"]);
$csvfile == ($_POST["CSV_File"]);
$CSV_File = htmlspecialchars($csvfile);
// MAKE CONNECTION
$conn  = mysql_connect("$mysqlserver", "$mysqllogin", "$mysqlpassword");

// IF CONNECTION CANNOT BE MADE QUIT AND GIVE AN ERROR MESSAGE
if (!$conn)
  {
  die('<h4>Could <u>Not</u> Connect To The Database</h4><hr>' . mysql_error());
  }
  
mysql_select_db("$mysqldb", $conn);


############################################
##  THIS IS WHERE I HAVE THE PROBLEM...
##  HOW DO I PASS THE INFO FROM THE PREVIOUS FORM
##  TO THIS ONE............................
############################################


$insert_value = ""; 
$get_columns = mysql_query("SELECT * FROM $mysqltbl");
$mysql_columns = mysql_fetch_field($get_columns);
foreach  ($mysql_columns as $value) {
$insert_value .= ($_POST['$value']);
}
?>

 

 

What would be the best way to pass on that info to the

import portion of the script and each one have a::

$value1 == ($_POST["value2"]);

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.