mercredi 19 mai 2021

What attribute's are appropriate for log-in credentials

I'm currently working on a school project to create a quiz program (local-host) to assess students based on their marks on the quiz. So in that project's database, I have a "student" table and also a "student_name" table. I would have put it in the same table but my teacher told me to put it into two different tables as a normalization step to reach 3nf (getting rid of "transitional functions")? Below are the pictures of my tables: (Sorry, it's in Malay) "murid"(student) table <no_kp_murid = "student's IC number"> <katalaluan = "password"> "nama_murid"(student_name) table <email_murid = "student's email"> <nama_murid = 'student's name>

So the problem is in the login page. Currently I'm using a "no_kp_murid"(IC number) - "katalaluan"(password) combination to log-in. So it logs in fine, but in the main_menu I'd like to display the "nama_murid"(student's name) attribute. The problem is, it displays the first student name registered and not the actual student-that-logged-in's name. Here's my code:

<?php
 session_start();
 include ('sambungan.php');

 if (isset($_POST['no_kp']))
 {
  $no_kp = $_POST['no_kp'];
  $katalaluan = $_POST['katalaluan'];
  $sql_nama_murid = 'select * from nama_murid';
  $return = mysqli_query($sambungan , $sql_nama_murid);
  $nama_murid = mysqli_fetch_array($return); // isytihar $nama_murid sbg pewakil table nama_murid
  $sql_murid = 'select * from murid';
  $result = mysqli_query($sambungan , $sql_murid);
  $jumpa = FALSE;
  while($murid = mysqli_fetch_array($result))
   {
    if($murid['no_kp_murid'] == $no_kp && $murid['katalaluan'] == $katalaluan)
    {
        $jumpa = TRUE;
        $_SESSION['username'] = $no_kp;
        $_SESSION['nama_murid'] = $nama_murid['nama_murid'];//this'd be where the error is
        $_SESSION['status'] = 'murid';
        header('Location: utama_murid.php');
        break;
    }
   }
if($jumpa == FALSE)
{
 $sql_guru = "select * from guru";
 $result = mysqli_query($sambungan , $sql_guru);
 while($guru = mysqli_fetch_array($result))
   {
     if($guru['no_kp_guru'] == $no_kp && $guru['katalaluan'] == $katalaluan)
       {
         $jumpa = TRUE;
         $_SESSION['username'] = $guru['no_kp_guru'];
         $_SESSION['nama_guru'] = $guru['nama_guru'];
         $_SESSION['status'] = 'guru';
         header('Location: utama_guru.php');
         break;
       }
   }
}
else
    echo "<script>alert('Kesalahan pada username atau password');
          window.location = 'login.php'</script> ";
}?>

 <title>Kuizrep - Log Masuk</title>
 <link rel='stylesheet' href='form.css'>

 <body>
    <div class="login">
      <img src="Logo%20Kuizrep.png" />
      <form class='login' action = 'login.php' method = 'post'>
        <input class="input" type="text" placeholder="no kad pengenalan" required = '' name = 'no_kp'/>
        <input class="input" type="password" placeholder="katalaluan" required = '' name = 'katalaluan' />
      <br>
      <br>
      <br>
      <button class = 'butang' type="submit"> Login </button>
      </form>
      <br>
      <centre><a href="signup.php">Pengguna Baharu?</a></centre>
     </div>

Any suggeesion's on what log-in credential combination I could use? I thought of putting the primary key of "murid"(student) table into the "nama_murid"(student's name) table so that I could use WHERE on he SQL query for calling the student's name but then I'd have to mess up my relationships and then I'd have to alter my other php codes in signup page etc. I'd really not have to do that. Any easier alternatives? Oh yeah, I code using html, and php and myphpadmin server. So no js pls. If you want any translations you can ask me I'll translate them.

"P.S: Sorry everything's in Malay and sorry if my code's messy. I'm a newbie"




Aucun commentaire:

Enregistrer un commentaire