Salve, dovrei risolvere il seguente problema: in pratica ho una pagina loginStud.php dove lo studente si logga (e fin qui tutto bene, sia sul controllo se è registrato o meno e sia sulla sessione(presumo)). Una volta loggato dovrebbe essere indirizzato a una pagina visualizza.php dove vengono mostrati in forma tabellare le materie e altre info con i rispettivi valori . Il problema è che fatto il login, vengo si indirizzato alla pagina visualizza.php, ma la tabella con i valori non compare, compare soltato l'immagine src caricata, insieme al CSS. Lascio di seguito: loginStud.php,visualizza.php,logout2.php,session2.php.
PS: mi scuso per il disordine nel codice, ho fatto tutto molto velocemente.
<?php
   include("config.php");
   session_start();
   
   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // matricola and password sent from form 
      
      $myusername = mysqli_real_escape_string($db,$_POST['Matricola']);
      $mypassword = mysqli_real_escape_string($db,$_POST['Pass']); 
      
      $sql = "SELECT * FROM STUDENTE WHERE Matricola = '$myusername' and Pass_Stud = '$mypassword'";
      $result = mysqli_query($db,$sql);
      $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
      //$active = $row['active'];
      
      $count = mysqli_num_rows($result);
      
      // If result matched $myusername and $mypassword, table row must be 1 row
		
      if($count == 1) {
        // session_register("myusername");
         $_SESSION['login_stud'] = $myusername;
         
         header("location: visualizza.php");
      }else {
         $error = "Your matricola or Password is invalid";
      }
   }
?>
<html>
   
   <head>
      <title>Login Studente</title>
      <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:400,500,600,700&display=swap">
     <link rel="stylesheet" href="style3.css">
      
   </head>
   <body>
        <div class="wrapper">
         <div class="title">
            Login Form
         </div>
         <form action="" method="post">
            <div class="field">
               <input type="text" name= "Matricola"required>
               <label>Matricola</label>
            </div>
            <div class="field">
               <input type="password" name="Pass" required>
               <label>Password</label>
            </div>
            
            <div class="field">
               <input type="submit" value="Login">
            </div>
            
         </form>
      </div>
           <!-- 
               <form action = "" method = "post">
                  <label>Matricola  :</label><input type = "text" name = "Matricola" class = "box"/><br /><br />
                  <label>Password  :</label><input type = "password" name = "Pass" class = "box" /><br/><br />
                  <input type = "submit" value = " Submit "/><br />
				  <br>
			
               </form> -->
   </body>
</html>
visualizza.php
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="refresh" content="5" >
    <link rel="stylesheet" type="text/css" href="style4.css" media="screen"/>
	<title> Registro </title>
</head>
<body>
    <header><img src="img2.png" width="300" height="300"/></header>
<?php
include('session2.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") { // verifica se la richiesta ricevuta è un POST
	 $conn = new mysqli("localhost","root","","scuola");
	 if ($conn->connect_error) {
            die("connessione fallita: " . $conn->connect_error);
        } 
        
		 $sql = "
                   SELECT Mat,Condotta,Italiano,Matematica,Storia,Informatica,Inglese,Chimica,Media,Ritardi,Uscite,Assenze,Note FROM REGISTRO
                ";
	echo '<table cellspacing="5" cellpadding="5">
      <tr> 
        <th>Matricola</th> 
        <th>Condotta</th> 
        <th>Italiano</th> 
        <th>Matematica</th>  
        <th>Storia</th> 
        <th>Informatica</th> 
        <th>Inglese</th> 
        <th>Chimica</th> 	
        <th>Media</th> 
        <th>Ritardi</th> 
        <th>Uscite</th> 
        <th>Assenze</th> 
         <th> Note </th>		
      </tr>';
            if ($conn->query($sql) === TRUE) {
  
        $row_mat = $row["Mat"];
        $row_condotta = $row["Condotta"];
        $row_italiano = $row["Italiano"];
        $row_matematica = $row["Matematica"];
		 $row_storia = $row["Storia"];
        $row_informatica = $row["Informatica"];
        $row_inglese = $row["Inglese"];
        $row_chimica = $row["Chimica"];
		 $row_media = $row["Media"];
        $row_ritardi = $row["Ritardi"];
        $row_uscite = $row["Uscite"];
        $row_assenze = $row["Assenze"];
		$row_note = $row["Note"];
         
      
        echo '<tr> 
                <td>' . $row_mat . '</td> 
                <td>' . $row_condotta . '</td> 
                <td>' . $row_italiano . '</td> 
                <td>' . $row_matematica . '</td> 
				 <td>' . $row_storia . '</td> 
                <td>' . $row_informatica . '</td> 
                <td>' . $row_inglese . '</td> 
                <td>' . $row_chimica . '</td> 
				 <td>' . $row_media . '</td> 
                <td>' . $row_ritardi . '</td> 
                <td>' . $row_uscite . '</td> 
                <td>' . $row_assenze . '</td> 
				<td>' . $row_note . '</td>            
              </tr>';
			  echo "<br>";
			echo "Effettua logout: <a href=logout2.php>Logout</a>";
    } else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
}
?>
	</table>
</body>
</html>
logout2.php
<?php
   session_start();
   
   if(session_destroy()) {
      header("Location: loginStud.php");
   }
?>
session2.php
<?php
   include('config.php');
   session_start();
   
   $user_check = $_SESSION['login_stud'];
   
   $ses_sql = mysqli_query($db,"select Matricola from STUDENTE where Matricola = '$user_check' ");
   
   $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
   
   $login_session = $row['Matricola'];
   
   if(!isset($_SESSION['login_stud'])){
      header("location:loginStud.php");
      die();
   }
?>