Javascript 将数据上传到网站

Javascript 将数据上传到网站,javascript,php,html,Javascript,Php,Html,我目前正在为我的网站制作一个网页。我的页面的目的是显示我员工的每日统计数据。例如,他们的绩效和客户满意度。我将按如下方式显示这些数据 <body> <table> <tr> <td>Bob</td> <!--Name--> <td>96%</td> <!--Customer Satisfaction--> <td>2%</td> <

我目前正在为我的网站制作一个网页。我的页面的目的是显示我员工的每日统计数据。例如,他们的绩效和客户满意度。我将按如下方式显示这些数据

<body>

<table>
  <tr>
    <td>Bob</td> <!--Name-->
    <td>96%</td> <!--Customer Satisfaction-->
    <td>2%</td> <!--48 hour callback-->
  </tr>
  <tr>
    <td>Jack</td> <!--Name-->
    <td>98%</td> <!--Customer Satisfaction-->
    <td>5%</td> <!--48 hour callback-->
  </tr>
</table>

</body>

上下快速移动
96% 
2% 
杰克
98% 
5% 

我想每天添加这些统计数据。我知道我可以每天晚上手动上传这些数字,但这似乎很乏味,因为我有30多名员工。我的问题是,有没有更简单的方法将数据上传到html文件?有没有办法向web服务器发送电子邮件,让代码扫描数据,然后获取这些号码并自动将这些号码更新到需要的位置?如有任何建议或想法,将不胜感激!谢谢。

您可以执行以下操作作为解决方案

  • 使用watchman工具()监视您更新数据的数据文件,当您更新该文件时,该数据文件将上载到您的网站
  • 在您的网站中编写一个端点来处理文件上载,该端点将保存上载的文件,解析其中的数据,并以所需的方式保存,以便在有人访问您的网站时显示它 编辑


    有关使用watchman的更多信息,请参考

    您可以执行以下操作作为解决方案

  • 使用watchman工具()监视您更新数据的数据文件,当您更新该文件时,该数据文件将上载到您的网站
  • 在您的网站中编写一个端点来处理文件上载,该端点将保存上载的文件,解析其中的数据,并以所需的方式保存,以便在有人访问您的网站时显示它 编辑


    有关使用watchman的更多信息,请参阅是。有很多方法可以做到这一点

    最标准的方法是让员工将数据上传到服务器,并将数据输入数据库,然后使用PHP根据数据库内容呈现HTML

    任务1-将数据获取到服务器 您的第一个任务是获取服务器上的数据电子邮件不会是实现这一点的方法。电子邮件使用SMTP/S和IMAP协议,这可能非常棘手,需要臭名昭著的错误(和庞大)库来处理。使用非常用户友好的HTTP/S协议来发布数据,您会更高兴

    基本上HTTP post是这样工作的。您在某些网页上添加了一个,您的员工可以在其中向您的服务器提交此数据。它看起来像这样

    <form action="data_receiving_endpoint.php" method="post">
        Username:<br/>
        <input type="text" name="username" placeholder="Please input your full name."/>
        Password:<br/>
        <input type="password" name="password" placeholder="Please input your password."/>
        How You Feel About Working for Me Today:<br/>
        <input type="text" name="feelings" placeholder="Please input your feelings."/>
        <input type="submit" value="Submit"/>
    </form>
    
    username=Jimmy%20John&password=iamjimmyjohn&feelings=You%27re%20the%20worst%20boss%20in%20the%20world!
    
    “%xx”符号是HTML表单数据中不支持的字符的十六进制代码。翻译后,此数据将变为

    username=Jimmy John
    &
    password=iamjimmyjohn
    &
    feelings=You're the worst boss in the world!
    
    任务2-在服务器中记录数据 您的下一个任务是获取员工的数据并将其存储在可用的位置,如数据库。对于这个例子,我假设您将使用,您可能会使用TBH

    接下来发生的事情需要发生在HTML表单中
    action
    引用的URI上。您需要在
    /data\u receiving\u endpoint.PHP
    处创建一个PHP文件。这将是一个脚本文件,将被执行以处理任何传入的请求

    此PHP文件需要获取post数据并将其提交到MySQLi数据库。它看起来像这样。如果你不熟悉语法,你会想复习一下

    <?php
        $dbhostname = 'localhost';
        $adminuser = 'thebossman';
        $adminpwd = 'secretPassword';
        $dbname = 'thebossmansdatabase';
        // connect to your database (it's its own server in a way)
        $connection = new mysqli($dbhostname, $adminuser, $adminpwd, $dbname);
        if ($connection->connect_error) {
            // if connection failed then abort
            header('HTTP/1.1 500 Internal Server Error');
            die('failed to establish connection');
        }
        // image you have a table named "DataTable"
        // first step is to validate the user's password
        // we can use variables from the post data by calling $_POST['variable name']
        $verifyCommand = 'SELECT * FROM DataTable WHERE username='.$_POST['username'];
        $result = $connection->query($verifyCommand);
        if ($result->num_rows == 0) {
            // the user is unknown, you should abort
            header('HTTP/1.1 403 Forbidden');
            die('user was not recognized.');
        }
        $row = $result->fetch_assoc();
        if ($row['password'] != $_POST['password']) {
            // the user cannot be authenticated
            header('HTTP/1.1 404 Unauthorized');
            die('The user was not authenticated.');
        }
        // now the user is authorized and you should update the database
        $updateCommand = 'UPDATE DataTable SET feelings='.$_POST['feelings'].' WHERE username='.$_POST['username'];
        if ($connection->query($updateCommand) !== TRUE) {
            // database update failed
            header('HTTP/1.1 500 Internal Server Error');
            die('database update failed');
        }
        // you're done. you can close the connection.
        $connection->close();
    php?>
    <!-- REMEMBER THE USER WILL BE SENT TO THIS PAGE SO THERE SHOULD BE SOME HTML BELOW THIS -->
    
    然后,在脚本执行的整个过程中,您的连接都可用。只需记住,你需要在底部

    <?php
        $connection->close();
    php?>
    
    
    
    从现在开始,生成显示并不困难。基本上你只是想出一个系统的方法来填充数据。例如,而不是

    <table>
        <head>
            <th>Name</th>
            <th>Feelings</th>
        </thead>
        <tbody>
        <tr>
            <td>Jimmy John</td>
            <td>You&#39;re the worst boss in the world!</td>
        </tr>
        <tr>
            <td>Jenna Whatever</td>
            <td>I don&#39;t mind you.</td>
        </tr>
        </tbody>
    </table>
    
    
    名称
    感情
    吉米·约翰
    你';你是世界上最糟糕的老板!
    珍娜,随便了
    我不知道';我不介意你。
    
    您可以这样做来动态生成页面

    <table>
        <head>
            <th>Name</th>
            <th>Feelings</th>
        </thead>
        <tbody>
    <?php
        $result = $connection->query('SELECT username, feelings FROM DataTable');
        while ($row = $result->fetch_assoc()) {
            echo '<tr><td>';
            // remember to escape special charaters
            echo htmlspecialchars($row['username']);
            echo '</td><td>';
            echo htmlspecialchars($row['feelings']);
            echo '</td></tr>';
        }
    php?>
    </tbody>
    </table>
    
    
    名称
    感情
    

    这基本上就是你想要的。

    是的。有很多方法可以做到这一点

    最标准的方法是让员工将数据上传到服务器,并将数据输入数据库,然后使用PHP根据数据库内容呈现HTML

    任务1-将数据获取到服务器 您的第一个任务是获取服务器上的数据电子邮件不会是实现这一点的方法。电子邮件使用SMTP/S和IMAP协议,这可能非常棘手,需要臭名昭著的错误(和庞大)库来处理。使用非常用户友好的HTTP/S协议来发布数据,您会更高兴

    基本上HTTP post是这样工作的。您在某些网页上添加了一个,您的员工可以在其中向您的服务器提交此数据。它看起来像这样

    <form action="data_receiving_endpoint.php" method="post">
        Username:<br/>
        <input type="text" name="username" placeholder="Please input your full name."/>
        Password:<br/>
        <input type="password" name="password" placeholder="Please input your password."/>
        How You Feel About Working for Me Today:<br/>
        <input type="text" name="feelings" placeholder="Please input your feelings."/>
        <input type="submit" value="Submit"/>
    </form>
    
    username=Jimmy%20John&password=iamjimmyjohn&feelings=You%27re%20the%20worst%20boss%20in%20the%20world!
    
    “%xx”符号是HTML表单数据中不支持的字符的十六进制代码。翻译后,此数据将变为

    username=Jimmy John
    &
    password=iamjimmyjohn
    &
    feelings=You're the worst boss in the world!
    
    任务2-在服务器中记录数据 您的下一个任务是获取员工的数据并将其存储在可用的位置,如数据库。对于这个例子,我假设您将使用,您可能会使用TBH

    接下来发生的事情需要发生在HTML表单中
    action
    引用的URI上。您需要在
    /data\u receiving\u endpoint.PHP
    处创建一个PHP文件。这将是一个脚本文件,将被执行以处理任何传入的请求

    此PHP文件需要获取post数据并将其提交到MySQLi数据库。它看起来像这样。如果你不熟悉语法,你会想复习一下

    <?php
        $dbhostname = 'localhost';
        $adminuser = 'thebossman';
        $adminpwd = 'secretPassword';
        $dbname = 'thebossmansdatabase';
        // connect to your database (it's its own server in a way)
        $connection = new mysqli($dbhostname, $adminuser, $adminpwd, $dbname);
        if ($connection->connect_error) {
            // if connection failed then abort
            header('HTTP/1.1 500 Internal Server Error');
            die('failed to establish connection');
        }
        // image you have a table named "DataTable"
        // first step is to validate the user's password
        // we can use variables from the post data by calling $_POST['variable name']
        $verifyCommand = 'SELECT * FROM DataTable WHERE username='.$_POST['username'];
        $result = $connection->query($verifyCommand);
        if ($result->num_rows == 0) {
            // the user is unknown, you should abort
            header('HTTP/1.1 403 Forbidden');
            die('user was not recognized.');
        }
        $row = $result->fetch_assoc();
        if ($row['password'] != $_POST['password']) {
            // the user cannot be authenticated
            header('HTTP/1.1 404 Unauthorized');
            die('The user was not authenticated.');
        }
        // now the user is authorized and you should update the database
        $updateCommand = 'UPDATE DataTable SET feelings='.$_POST['feelings'].' WHERE username='.$_POST['username'];
        if ($connection->query($updateCommand) !== TRUE) {
            // database update failed
            header('HTTP/1.1 500 Internal Server Error');
            die('database update failed');
        }
        // you're done. you can close the connection.
        $connection->close();
    php?>
    <!-- REMEMBER THE USER WILL BE SENT TO THIS PAGE SO THERE SHOULD BE SOME HTML BELOW THIS -->
    
    然后,在脚本执行的整个过程中,您的连接都可用。只需记住,你需要在底部

    <?php
        $connection->close();
    php?>
    
    
    
    从现在开始,生成显示并不困难。基本上你只是想出一个系统的方法来填充数据。例如,而不是

    <table>
        <head>
            <th>Name</th>
            <th>Feelings</th>
        </thead>
        <tbody>
        <tr>
            <td>Jimmy John</td>
            <td>You&#39;re the worst boss in the world!</td>
        </tr>
        <tr>
            <td>Jenna Whatever</td>
            <td>I don&#39;t mind you.</td>
        </tr>
        </tbody>
    </table>
    
    
    名称
    感情
    吉米·约翰
    Y