Jump to content

Submitting form data to database with PHP


thenorman138

Recommended Posts

I have an upload page that users for a small company use to upload/submit csv sheets daily. They are always the same, 235 fields in the same order. I currently have a preview button that shows the CSV in a table/form (for edits) and a submit button that has been successfully inserting the CSV into a 235 field staging table in the database.

 

I now need to submit the preview form/table with any edits the user might make. I added a 'Submit' button to the preview form, but I haven't gotten it to work yet. I have an array that works on the first page, taking all 235 fields and naming them to either insert into the database or display in the preview table. In order to submit from the table, including any edits that were made, I think I need to create a new CSV from the html form/table and insert that similarly, but I've never done this and I'm unsure now. This is the code for the preview form that is built from the CSV that is uploaded:

 

if(isset($_POST['preview']))
{
ini_set('auto_detect_line_endings', true);
 
$file = $_FILES["file"]["tmp_name"];
$handle = fopen($file, "r");
$maxPreviewRows = PHP_INT_MAX;  // this will be ~2 billion on 32-bit system, or ~9 quintillion on 64-bit system
$hasHeaderRow = true;
 
echo '<table>';
 
/*WE WILL NEED TO QA CONDITIONS AND HIGHLIGHT IN RED HERE. ALSO NEED BORDER STYLINGS*/
 
if ($hasHeaderRow) {
   $headerRow = fgetcsv($handle);
   echo '<thead><tr>';
   foreach($headerRow as $value) {
       echo "<th>$value</th>";
   }
   echo '</tr></thead>';
}
 
echo '<tbody>';
 
$rowCount = 0;
while ($row = fgetcsv($handle)) {
   echo '<tr>';
   foreach($row as $value) {
       echo "<td>$value</td>";
   }
   echo '</tr>';
 
   if (++$rowCount > $maxPreviewRows) {
       break;
   }
}
echo '</tbody></table>';
 
}

 

?>
 
 
 
 
 
 

post-204074-0-71347900-1493702401_thumb.png

Link to comment
Share on other sites

 a 235 field staging table in the database.

 

Oh say it's not so. A database is not a spreadsheet. I would want to see one of these 235 field files before I could tell you how to go about this. If you can, attach or Pm the file. I only need to see a couple rows of data with headers.

 

What you need is an ETL process (Extract, Transform, Load). 

https://en.wikipedia.org/wiki/Extract,_transform,_load

Link to comment
Share on other sites

I know it's not great, but unfortunately a very outdated utilities system is being used and this is how I've been tasked to do it. I'm splitting everything into smaller tables, but it hits the staging table first. Sorry, did you want me to post one of the CSV files that's being uploaded initially? Or am I posting something different?

Link to comment
Share on other sites

I would like to see the initial file. Some details of the common edits would be helpful and details on how the data is generated in the first place. A brief summary of what this is all about and how it will be used would be helpful as well. Think as though nothing exists and we needed to develop a system from scratch to accomplish your purposes.

Link to comment
Share on other sites

Thanks very much, I just emailed you. It doesn't look like I can PM. Please let me know if any of that is unclear. Also, the PHP file I attached has the submit code as well so it's pretty lengthy, but the code for the preview window is near the top

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.