无法控制用户可以在 php 中看到的内容?

Unable to control what the user can see in php?

我想控制用户在我的系统中可以看到的内容。一个人告诉我,我应该检查用户 ID 是否与讲师 ID 匹配。讲师只能看到自己的数据,不能看到任何其他讲师的数据。我试过了,但现在不起作用。

我也遇到了这些错误:

Notice: Undefined index: userID in C:\XAMPP\htdocs\statistics\lecturer.php on line 5

Notice: Undefined index: lecID in C:\XAMPP\htdocs\statistics\lecturer.php on line 6

Fatal error: Call to undefined function mysql_fecth_row() in C:\XAMPP\htdocs\statistics\lecturer.php on line 24

我也测试了查询并得到:

我觉得有点奇怪。我有 tables 个具有用户 ID、用户名和类型的用户,以及一个具有讲师 ID 和讲师姓名的讲师 table。

 include 'connect.php';

   $userID=mysql_real_escape_string($_POST['userID']);
   $lecID=mysql_real_escape_string($_POST['lecID']);
   $year = mysql_real_escape_string($_POST['year']);
   $lecturer = mysql_real_escape_string($_POST['lecturer']); // Don't forget to handle the SQL Injections ...
   $years     = array(
      2005,
      2006,
      2007
   );
  $lecturers = array(
     'dimopoulos',
     'lagkas',
     'kehagias',
     'chrysochoou'
  );

 if(isset($_POST['submit'])){
       if($userID==$lecID){
         $check=("SELECT users.uid,lecturer.lec_id FROM users,lecturer");
          $row=mysql_fecth_row($check);

        if($row[0]==$lecturer){

            if (in_array($lecturer, $lecturers) && in_array($year, $years)) {

                 $sql = "SELECT unit_name,a1,a2,a3,l1,l2,l3,l4,l5,l6,l7,lavg,r1,r2,u1,u2,u3 FROM $lecturer WHERE year=$year";
               $result = mysql_query($sql);
        }

        else {
            echo "No data found";
        }


      }
    }
 }


    ?>
  <html>
  <head>
  <link rel="stylesheet" type="text/css" href="../../statistics/style.css">
  </head>
  <body>
     <div id="container">
      <table id="table" width="900" border="1" cellspacing="1">
    <tr>
    <td>Unit Name</td>
    <td>A1 </td>
    <td>A2 </td>
    <td>A3 </td>
    <td>L1 </td>
    <td>L2 </td>
    <td>L3 </td>
    <td>L4 </td>
    <td>L5 </td>
    <td>L6 </td>
    <td>L7 </td>
    <td>LAVG </td>
    <td>R1 </td>
    <td>R2 </td>
    <td>U1 </td>
    <td>U2 </td>
    <td>U3 </td>


</tr>

<?php
    while($unit=mysql_fetch_assoc($result)){
        echo "<tr>";
        echo "<td>".$unit['unit_name']."</td>";
        echo "<td>".$unit['a1']."</td>";
        echo "<td>".$unit['a2']."</td>";
        echo "<td>".$unit['a3']."</td>";
        echo "<td>".$unit['l1']."</td>";
        echo "<td>".$unit['l2']."</td>";
        echo "<td>".$unit['l3']."</td>";
        echo "<td>".$unit['l4']."</td>";
        echo "<td>".$unit['l5']."</td>";
        echo "<td>".$unit['l6']."</td>";
        echo "<td>".$unit['l7']."</td>";
        echo "<td>".$unit['lavg']."</td>";
        echo "<td>".$unit['r1']."</td>";
        echo "<td>".$unit['r2']."</td>";
        echo "<td>".$unit['u1']."</td>";
        echo "<td>".$unit['u2']."</td>";
        echo "<td>".$unit['u3']."</td>";
        echo "</tr>";    
    }
?>
</table>
</div>

登录后使用phpSession存储用户信息,然后show/hide基于它们的数据。

从这里查看文档- PHP SESSION

嗯,一方面(如您的错误消息所示)mysql_fecth_row 不是 PHP 函数。那里有错字 - 应该是 mysql_fetch_row.