PHP - No se como validar

 
Vista:

No se como validar

Publicado por A (1 intervención) el 06/05/2021 18:33:51
Me podríais ayudar a que mi página validar mire un array que se llama "data.php" y si está el alumno muestre su nota en una pagina llamada "alumne.php"? He conseguido hacer la parte del profesor que muestra todas pero esta parte no, gracias.
Adjunto las partes de mi codigo
------------------------------------------------------------------------------------------------------------------
Esta es la pagina "validar.php":
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
	$nom = $_POST ['nom'];
    $password = $_POST ['password'];
	$profe = $profe;
 
echo "usuari: $nom<br>";
echo "password: $password<br>";
 
	if ($nom == 'profe' && $password == 'profe') {
		session_start();
		$_SESSION['nom'] = $nom;
		header("location: profe.php");
	}elseif(isset($nom)){
		trobat := false;
		$i=0;
		while (!trobat and $i<count($data)) {
			if($nom == 'user' && $password == 'password'){
				trobat=true;
				i++;
			}
			if (trobat==true){
				header("location: alumne.php");
			}
		}
 
	}else{
		#Per si intenten accedir directament desde la url
		header("location: login.html");
	}
?>
-------------------------------------------------------------------
Esta es la pagina "data.php":
1
2
3
4
5
6
7
8
9
<?php
 $data = array (
 array("user" => "joan",   "password" => "jn", "nom" => "Joan Feliu Ventura",     "nota" => 6),
 array("user" => "marta",  "password" => "ma", "nom" => "Marta Sotorra Vives",    "nota" => 4),
 array("user" => "andreu", "password" => "au", "nom" => "Andreu Vernils Sorolla", "nota" => 9),
 array("user" => "anna",   "password" => "aa", "nom" => "Anna Roig Verdaguer",    "nota" => 10),
 array("user" => "pere",   "password" => "pe", "nom" => "Pere Altamira Forn",     "nota" => 3),
 );
?>
--------------------------------------------------------
Esta la página "login.html" para iniciar sesion:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Document</title>
</head>
<body>
 <form action="validar.php" method="post">
 <font style="vertical-align: inherit;"><b>Usuari: </b></font>
 <input type="text" name="nom" id="nom" required autofocus>
 <br>
 <br>
 <font style="vertical-align: inherit;"><b>Contrasenya: </b></font>
 <input type="password" name="password" id="password" required>
 <br><br>
 <input type="submit" name="accedir" value="Accedir">
 </form>
</body>
</html>
-----------------------------------------------------------------
Esta es la pagina "alumne.php" que no se si está bien:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
 session_start();
 if ($_SESSION['nom'] == 'user'){
 include_once("data.php");
 }else{
 #Per si intenten accedir directament desde la url
 header("location: login.html");
 }
?>
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <link rel="stylesheet" type="text/css" href="alumne.css">
 <title>Alumne</title>
</head>
<body>
 <h1>Vista alumne</h1>
 <table>
 <?php
 foreach ($data as $user) {
 if ($_SESSION['nom'] ==  $user["user"]){
 echo '<tr>
 <td><b>' . $user["nom"] . '</b></td>
 <td>' . $user["nota"] . '</td>
 </tr>';
 }
 }
 ?>
 </table>
 <br>
 <button onclick="location='logout.php'">Eliminar sessió</button>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder