0

I have a project where I can upload a specific excel-file on a website. The excel-file is shown on the website as a html table. Under the table is a button to upload the table in a database. Therefore I save the table cells in an array (in JS-function). At the end I pass the array to a second php-file, where I upload the array data in a database. On last upload I want to show a pop-up. I have these files:

upload.php

if (isset($_FILES['file']) && !empty($_FILES['file'])) {
    //show excel file as table on website
    <form  action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
       <button id="exBtnHoch" name="exBtnHoch" onclick="saveInArray()" type="button"  class="btn btn-success btn-block">Excel-Datei hochladen</button>
       </br></br></br></br></br></br>  
    </form>
}

excelEinlesen.php

include "pop_up.php";

if(isset($_POST['daten'])){    //checks if array is passed
    //if successfull then do something like:
    echo '<script type="text/javascript">showPOP_UP();</script>';
}
//EDIT
function a (){}      //they are called in the if-part

function b (){}

EDIT: pop_up.php: HTML-Code

<!doctype html>
<html lang="de">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="../css/bootstrap.min.css">
        <script type="text/javascript" src="js/excelEinlesen.js"></script>
    </head>
    <body>
    <div class="modal fade" id="pop_upHochgeladen" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="false">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Speichern</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
            <div class="modal-body">
                Die Daten des Mitarbeiters wurden erfolgreich in die Datenbank geschrieben.
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-warning" onClick="geheZuHome()">Zurück zur Startseite</button>
                <button type="button" class="btn btn-warning" onClick="window.location.href=window.location.href">Weitere Datei hochladen</button>
            </div>
            </div>
        </div>
    </div>
    </body>
</html>

AND

excelEinlesen.js

function saveInArray(){
    //save table cells in array
    //at the end pass array to excelEinlesen.php
}

function showPOP_UP(){
    $('#pop_up').modal('show');   
}

I tried to echo it and searched the whole internet without any satisfying solutions. First had a second onclick in upload.php and it worked, but I want to call the JS-function in a specific case without onclick.

I don't know if this a problem, but I have different folders for my files: "js" and "php".

Eddy_SPL
  • 27
  • 6
  • 3
    Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Masivuye Cokile May 14 '19 at 12:50
  • So what _does_ happen? You should probably show the code of `pop_up.php` Have you checked your browser console for errors? – Patrick Q May 14 '19 at 12:50
  • None of the code that you're showing includes/references `excelEinlesen.js` – Patrick Q May 14 '19 at 12:55
  • @Patrick Q no error is shown in the console – Eddy_SPL May 14 '19 at 12:59
  • Sorry, forgot to include... i edited it in excelEinlesen.php – Eddy_SPL May 14 '19 at 12:59
  • @Masivuye Cokile thanks, but I don't see what to do when I want back to client side – Eddy_SPL May 14 '19 at 13:07
  • You now have your reference to the js file before the HTML. That's not going to work. Why don't you just put that line _inside_ `pop_up.php`? Perhaps in the `head` section. – Patrick Q May 14 '19 at 14:10
  • thanks for your advise, I will try it tomorrow – Eddy_SPL May 14 '19 at 14:45
  • I tried, but it didn't helped, is there else something with the order ? I have some functions to short the code in excelEinlesen.php, maybe that's a problem, because in debug mode he goes in the functions after the "if isset" – Eddy_SPL May 15 '19 at 06:03
  • I don't know the answer to your question, but I highly recommend to use restful API to separate the client logic and server logic. Also, if you use restful API the page is not loaded after any change. – tomer raitz May 15 '19 at 07:12
  • does nobody have an idea? – Eddy_SPL May 17 '19 at 08:29

0 Answers0