如何显示弹出窗口,其中包含从表中选择从ID获取数据的数据


How can I display popup window with select data from table that fetch data from ID?

我是PHP和MySQL的初学者。我可以在 MySQL 数据库中的表中显示数据。没关系。但我想要的是知道如何显示一个弹出窗口,其中包含表中的选定数据。

到目前为止,我已经这样做了,但是我需要的是当用户单击或选择表格行时,必须在包含选择数据的表格附近出现一个弹出窗口。

这是我的代码,请告诉我我必须做什么:

<?php
include('config.php');
?>
<html>
  <head>
    <title>Event Patrol</title>
  </head>
  <body>
    <br />
    <center>
    <?php
    $conn = mysql_connect('I have', 'I have', 'I have');
    mysql_select_db('I have', $conn);
    echo '<table>';
    '<tr>';
    '<td>Event</td>';
    '<td>Record Date</td>';
    '</tr>';
    $sql = "SELECT * from people where PersonId = '".$_GET["PersonId"]."'";
    $rs = mysql_query($sql,$conn) or die(mysql_error());
    while($result= mysql_fetch_array($rs)) {
        echo '<tr>
        <td>'.$result["Event"].'</td>
        <td>'.$result["RecordDate"].'</td>
        </tr>';
    }
    echo '</table>';
    ?>
    </div>
    </center>
    <div id="r" style="width:600px; align:centre"> </div>
    <center>
      <div id="content">
      <?php
      // Open database connection
      $con = mysql_connect("sql14.cpt1.host-h.net","rootaccess1","Screen_1");
      mysql_select_db("sentinelcrm", $con);
      $sql = "SELECT * FROM people";
      $result = mysql_query($sql);
      echo '<table cellpadding="5" cellspacing="0" border="1">';
      echo '<tr>';
      echo '<th>ID</th>';
      echo '<th>Event</th>';
      echo '<th>Control Room</th>';      
      echo '<th>Date</th>';   
      echo '<th>Site ID </th>';
      echo '<th>Action</td>';
      echo '</tr>';
      while ($rows = mysql_fetch_array($result)) {
          echo    '<tr>';
          echo    '<td>';
          echo    $rows['PersonId'];
          echo'</td>';
          echo    '<td>';
          echo $rows['Event'];
          echo '</td>';
          echo    '<td>';
          echo $rows['Control_Room_ID'];
          echo '</td>';
          echo    '<td>';
          echo $rows['RecordDate'];
          echo '</td>';
          echo '<td><a href="" >';
          echo $rows['Site_ID'];
          echo '</a></td>';
          echo '<td><input type="button" value="Edit" id="opener"/>';
          echo  '</tr>';
      }
      ?>
      </div>
    </center>
  </body>
</html>

您的代码中存在漏洞:

$sql= "SELECT * from people where PersonId = '".$_GET["PersonId"]."'";

由于您尚未检查此用户输入中的内容,因此黑客可以注入自己的 SQL,并以您不希望的方式在您的数据库上运行它。在这个库的情况下,黑客绝对不能运行任何东西,因为它必须在你的SELECT查询的上下文中有意义,而且(谢天谢地)这个库不支持一次运行许多查询。这将允许他们发布DELETEDROP或其他破坏性的东西。

尽管如此,黑客可以修改SELECT语句,让自己访问他们不应该访问的帐户或数据。此特定查询可能不敏感,但尽管如此,安全性是您应该始终拥有的心态,而不仅仅是在您认为它很重要的时候。

消除安全漏洞的一种简单方法是将数字转换为整数(假设此字段确实是整数而不是字符串变量)。这并不理想,但它会起作用:

$personId = (int) $_GET["PersonId"];
$sql= "SELECT * from people where PersonId = '{$personId}'";

现在这是安全的。但是,建议同时执行以下操作:

  • 切换到现代库,如 PDO/mysql 或 mysqli,因为您的库已弃用
  • 使用查询参数化(搜索它)