使用带有php变量的javascript实时更新sql表

时间:2019-03-10 23:32:04

标签: javascript php

好的,所以我创建了一个页面,该页面通过使用javascript每五秒钟刷新一次表格来实时更新而不刷新。该表分别存储在getTable.php中

<div id="table1"></div>
<script type="text/javascript">
$(document).ready(function(){
  refreshTable();
});

function refreshTable(){
    $('#table1').load('pickTable.php?user=<?php echo $user ?>&password=<?php echo $pass?>', function(){
       setTimeout(refreshTable, 5000);
    });
}

我的问题是我正在使用登录屏幕页面(index.php)中的表单数据转到homeTable.php(该表单数据用于从SQL表等中加载配置文件)getTable。 php还需要SQL登录才能提取数据。参见下面的getTable.php:

<table>
    <thead>
        <tr>
            <th><b>xxx1</b></th>
            <th><b>xxx2</b></th>
        </tr>
    </thead>
    <tbody>
    <?php

$connection_string = 'xxxxconnectionstring';

$user = $_POST["userid"];
$user = strtoupper($user);
$pass = @$_POST["password"];
$date = date(Ymd);

$connection = odbc_connect( $connection_string, $user, $pass ); 

if (((int) date('H', time())) >= 14) {

$sqlstring = "SELECT xxx FROM xxx";

;} 
elseif (((int) date('H', time())) < 14) {

$sqlstring = "SELECT xxx FROM xxx";}

$result = odbc_exec($connection, $sqlstring);

        while($row = odbc_fetch_array($result)) {
        ?>
            <tr>
                <td><?php echo ucwords(strtolower($row['xxxx1']))?>
                 <i class="fas fa-medal icon"></i></td>
                <td><?php echo $row['xxxx2']?></td>
            </tr>

        <?php
        }
        ?>
        </tbody>
        </table>

我目前已经通过使用php回显表单数据来解决此问题,但是由于查看源会显示日志中的详细信息,因此这显然是不安全的。

我的问题是,我该如何解决?有没有更好的方法来执行以上操作...

0 个答案:

没有答案