简体   繁体   English

如何只允许注册用户访问他们在mysql数据库中的信息?

[英]How to allow only registered users to have access to their information in mysql database?

I am setting up a student portal for a basci school.我正在为 basci 学校建立一个学生门户。 In the portal, students should be able to access their grades, courses, course materials, messages from their tutors and also view their payment details and how much they owe the school.在门户中,学生应该能够访问他们的成绩、课程、课程材料、来自导师的消息,还可以查看他们的付款详细信息以及他们欠学校的金额。

I have mysql tables ( 8 tables in all) with various relationships that is linked to their STUDENT ID.我有 mysql 表(总共 8 个表),其中包含链接到学生 ID 的各种关系。

I want each student to be able to login using username and password - I have the script already with a users table that stores the username and password credentials.我希望每个学生都能够使用用户名和密码登录 - 我已经有一个带有用户表的脚本,用于存储用户名和密码凭据。

Here are my questions:以下是我的问题:

  1. How to a create a page (php preferred) that will display ALL the information to each student such that each student can ONLY view their records?如何创建一个页面(首选 php)来向每个学生显示所有信息,以便每个学生只能查看他们的记录?
  2. How do I write the query such that only resources belonging to user can be viewed by that user?如何编写查询,以便该用户只能查看属于该用户的资源?
  3. There are about 3000 students and each student will register and be able to access their own - grades, Financials (bills and payments), courses, exam results, accommodation issues etc.大约有 3000 名学生,每个学生都将注册并能够访问自己的成绩、财务(账单和付款)、课程、考试成绩、住宿问题等。
  4. There are 500 Tutors and they should be able to also access their individual pages such that they can post grades, and generate assignments that will post to all students registered for that course.有 500 名导师,他们还应该能够访问他们的个人页面,以便他们可以发布成绩,并生成将发布给所有注册该课程的学生的作业。

Points to note:注意事项:

  1. I have the mysql tables to handle all the information - working.我有 mysql 表来处理所有信息 - 工作。
  2. I have the forms with php script to post data to all the forms - working.我有带有 php 脚本的表单,可以将数据发布到所有表单 - 工作。
  3. I have registration and login forms already with their php scripts - working.我已经使用他们的 php 脚本注册和登录表单 - 正在工作。

The ONLY problem is how to query the relational tables such that each registered user only sees his or her information only.唯一的问题是如何查询关系表,使每个注册用户只能看到他或她的信息。 Information is viewed based on the user.信息是基于用户查看的。

If anyone can point me in the right direction, it would be appreciated.如果有人能指出我正确的方向,将不胜感激。 Thank you.谢谢你。

Firstly you dont ask such questions so you wont get down voted and blocked now let me help feel free to contact me and upvote please i am new too and read more on querying database you might not be this lucky next time首先,你不会问这样的问题,所以你不会被投票和阻止,现在让我帮助随时联系我并投票,请我也是新人,阅读更多关于查询数据库的信息,下次你可能不会这么幸运

   //lets say showstudentsrecordpage.php after they are logged in, you use a cookie a session up to you get their auto incremented ids from database when they log in and query any table you want to with that id

    //create a table so you can show that user info after query

                <table>
    <th>sTUDENT NAME</th>
    <th>sTUDENT rrecord</th>
    <th>sTUDENT subject</th>

           // showstudentsrecordpage.php
           $studentcookieafterloggedin = $_COOKIE['userid']; //userid of student who logged in successfully
          $studentcookieafterloggedin = mysqli_escape_string($con, $studentcookieafterloggedin);

          $bringtheirrecordout = "SELECT FROM mayberecordstable WHERE id= '$studentcookieafterloggedin'";

          $runthequery = mysqli_query($con, $bringtheirrecordout);

        //variable $con is your connection parameters
               if (mysqli_num_rows($runthequery) < 1){
                Do what you want here if that user id is not found probably a redirect or something anything you want
              }

          //you dont need a while loop since it is only one record for a student if it is multiple records for different students then while loop is needed

          $fetcharray = mysqli_fetch_array($runthequery);

  //this are my own parameters just change it to your own database values

                 $id = $fetcharray['id'];
                 $studentname = $fetcharray['studentname'];
                 $studentgrades = $fetcharray['studentgrades'];
                 $subjects = $fetcharray['subjects'];'

          then show it 

        <div>
//continue your table for it here
             <tr>
              <td><?php echo $studentname ?></td>
              <td><?php echo $studentgrades ?></td>
              <td><?php echo $subjects ?></td>
             </tr>
</table>

        </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM