I am attempting to take a non parsed file from one table field. Parse the file and place the result into a table with corresponding fileds. Does anyone know how to do this using a form. I currently have this code writen. Thus far i have created two functions. one gets all the file names within the table,and the second that gets all the tables within my dba. I want the form to also parse the selected file into the selected table when i hit submit. Does anyone have suggestions. Below is my code for my from and functions. I have also writen a script that will parse a file on the server but not take a file from the table and parse it I want to take a file from the table and parse it. I have also added the code that parse from a file. If anyone knows how i might be able to modify this code to parse from the chosen value in the opion let me know.
<?php
first get a mysql connection as per the FAQ
$hostname_mydba = "localhost";
$database_mydba = "ozarkDB";
$username_mydba = "user";
$password_mydba = "pw";
$mydba = mysql_connect($hostname_mydba, $username_mydba, $password_mydba) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_mydba);
$fcontents = file ('OzarkDB3.txt') or die("could not get file");
# expects the csv file to be in the same dir as this script
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
// echo $line;
$arr = explode("\t", $line);
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','
$sql = "INSERT INTO 2004Results (Bib, firstName, lastName, Address, City, State, Zip, Email, FinTimeOfDay ) ".
"VALUES ('". implode("','", $arr) ."')";
//('$fileName', '$fileSize', '$fileType', '$content')";
//echo $query;
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
}
?>
function getTableName(){
Global $connection;
hookUpDb();
$result = mysql_list_tables('ozarkDB');
while ($row = mysql_fetch_row($result)) {
print("<option value=\"$id\">
$row[0]</option>\n");
}
mysql_free_result($result);
mysql_close($connection);
}
function getFileName(){
Global $connection;
hookUpDb();
$query = "SELECT fileName
FROM result_files";
$result = mysql_query($query,$connection);
while ($row = mysql_fetch_row($result)){
$id = $row[0];
$fileName = unFormatData($row[0]);
print("<option value=\"$id\">
$fileName</option>\n");
}
mysql_free_result($result);
mysql_close($connection);
}
<?php
if($txtId != "" && $txtId2 != ""){
doUpdate($txtId,$txtId2);
print("Database updated.");
}elseif($submit!="" && $txtId == "" && $txtId2 == ""){
doInsert($txtId,$txtId2);
print("Data inserted.");
}
?>
<?php
//create the global variable $my_string or you may get a warning
global $my_string;
global $my_table;
?>
<form method="post" enctype="multipart/form-data">
<table class="formBg" align="center" width="42%" border="1" cellspacing="0" cellpadding="2">
<tr valign="top">
<td width="43%">Choose file here</td>
<td width="57%">
<select class="dropdownMedium" name="text_id">
<option selected value="0">--- Choose file here ---</option>
<?php getFileName(); ?>
</select>
<input class="medium" type="hidden" name="txtId" value="<?php print(unFormatData($row[0])); ?>">
</td>
</tr>
<tr valign="top">
<td width="43%">Choose table here</td>
<td width="57%">
<select class="dropdownMedium" name="table_id">
<option selected value="0">--- Choose table here ---</option>
<?php getTableName(); ?>
</select>
<input class="medium" type="hidden" name="txtId2" value="<?php print(unFormatData($row[1])); ?>">
</td>
</tr>
<tr>
<tr valign="top">
<td width="43%"> </td>
<td width="57%">
<input class="button" type="submit" name="submit" value="Submit">
<input class="button" type="reset" name="reset" value="Reset">
</td>
</tr>
</table>