Compare commits

..

6 Commits

8 changed files with 791 additions and 123 deletions
+214 -65
View File
@@ -1,78 +1,227 @@
CREATE DATABASE IF NOT EXISTS Aeroporto; DROP DATABASE IF EXISTS aeroporto;
USE Aeroporto; CREATE DATABASE aeroporto;
USE aeroporto;
-- phpMyAdmin SQL Dump
-- version 5.1.2
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Creato il: Mar 31, 2026 alle 06:17
-- Versione del server: 5.7.24
-- Versione PHP: 8.3.1
CREATE TABLE PASSEGGERO ( SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
idPassaporto VARCHAR(20) PRIMARY KEY, START TRANSACTION;
cognome VARCHAR(50) NOT NULL, SET time_zone = "+00:00";
nome VARCHAR(50) NOT NULL,
nazionalita VARCHAR(50),
dataNascita DATE,
email VARCHAR(100)
);
CREATE TABLE VOLO (
numeroVolo VARCHAR(10) PRIMARY KEY,
compagnia VARCHAR(50) NOT NULL,
destinazione VARCHAR(50) NOT NULL
);
CREATE TABLE PRENOTAZIONE ( /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
idPrenotazione INT AUTO_INCREMENT PRIMARY KEY, /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
dataPrenotazione DATE NOT NULL, /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
prezzo DECIMAL(10, 2), /*!40101 SET NAMES utf8mb4 */;
classe VARCHAR(20),
idPassaporto VARCHAR(20),
numeroVolo VARCHAR(10),
FOREIGN KEY (idPassaporto) REFERENCES PASSEGGERO(idPassaporto),
FOREIGN KEY (numeroVolo) REFERENCES VOLO(numeroVolo)
);
CREATE TABLE BAGAGLIO ( --
idBagaglio INT AUTO_INCREMENT PRIMARY KEY, -- Database: `aeroporto`
dataImbarco DATE NOT NULL, --
peso DECIMAL(5, 2),
smarrito TINYINT(1),
idPassaporto VARCHAR(20),
FOREIGN KEY (idPassaporto) REFERENCES PASSEGGERO(idPassaporto)
);
INSERT INTO PASSEGGERO (idPassaporto, cognome, nome, nazionalita, dataNascita, email) VALUES -- --------------------------------------------------------
--
-- Struttura della tabella `bagaglio`
--
CREATE TABLE `bagaglio` (
`idBagaglio` int(11) NOT NULL,
`dataImbarco` date NOT NULL,
`peso` decimal(5,2) DEFAULT NULL,
`smarrito` tinyint(1) DEFAULT NULL,
`idPassaporto` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dump dei dati per la tabella `bagaglio`
--
INSERT INTO `bagaglio` (`idBagaglio`, `dataImbarco`, `peso`, `smarrito`, `idPassaporto`) VALUES
(1, '2024-09-01', '15.50', 0, 'AB12345'),
(2, '2024-10-05', '20.00', 0, 'XY98765'),
(3, '2024-10-05', '10.50', 0, 'XY98765'),
(4, '2024-12-05', '23.00', 0, 'US55555'),
(5, '2024-12-15', '22.00', 1, 'US55555'),
(6, '2024-12-20', '18.00', 0, 'US55555'),
(7, '2024-12-25', '12.00', 0, 'US55555'),
(8, '2024-09-15', '19.00', 0, 'FR11111'),
(9, '2024-11-30', '25.00', 0, 'CA77777');
-- --------------------------------------------------------
--
-- Struttura della tabella `passeggero`
--
CREATE TABLE `passeggero` (
`idPassaporto` varchar(20) NOT NULL,
`cognome` varchar(50) NOT NULL,
`nome` varchar(50) NOT NULL,
`nazionalita` varchar(50) DEFAULT NULL,
`dataNascita` date DEFAULT NULL,
`email` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dump dei dati per la tabella `passeggero`
--
INSERT INTO `passeggero` (`idPassaporto`, `cognome`, `nome`, `nazionalita`, `dataNascita`, `email`) VALUES
('AB12345', 'Rossi', 'Marco', 'Italiana', '1980-05-15', 'marco.rossi@email.it'), ('AB12345', 'Rossi', 'Marco', 'Italiana', '1980-05-15', 'marco.rossi@email.it'),
('XY98765', 'Bianchi', 'Luca', 'Italiana', '1992-10-20', 'luca.bianchi@email.it'), ('CA77777', 'Wilson', 'Emma', 'Canada', '1998-12-25', 'emma.w@ca.com'),
('US55555', 'Smith', 'John', 'USA', '1975-03-12', 'john.smith@usmail.com'),
('FR11111', 'Dupont', 'Jean', 'Francia', '1988-07-14', NULL),
('DE22222', 'Muller', 'Hans', 'Germania', '1990-11-30', 'hans.m@de.com'), ('DE22222', 'Muller', 'Hans', 'Germania', '1990-11-30', 'hans.m@de.com'),
('ES33333', 'Garcia', 'Maria', 'Spagnola', '1995-02-28', 'maria.g@es.com'), ('ES33333', 'Garcia', 'Maria', 'Spagnola', '1995-02-28', 'maria.g@es.com'),
('RO99999', 'Romano', 'Giulia', 'Italiana', '2000-01-01', NULL), ('FR11111', 'Dupont', 'Jean', 'Francia', '1988-07-14', NULL),
('NE00000', 'Neri', 'Fantasma', 'Italiana', '1999-09-09', 'neri@test.it'),
('PT44444', 'Silva', 'Joao', 'Portoghese', '1985-06-10', 'joao@pt.com'), ('PT44444', 'Silva', 'Joao', 'Portoghese', '1985-06-10', 'joao@pt.com'),
('CA77777', 'Wilson', 'Emma', 'Canada', '1998-12-25', 'emma.w@ca.com'), ('RO99999', 'Romano', 'Giulia', 'Italiana', '2000-01-01', NULL),
('NE00000', 'Neri', 'Fantasma', 'Italiana', '1999-09-09', 'neri@test.it'); ('US55555', 'Smith', 'John', 'USA', '1975-03-12', 'john.smith@usmail.com'),
('XY98765', 'Bianchi', 'Luca', 'Italiana', '1992-10-20', 'luca.bianchi@email.it');
INSERT INTO VOLO (numeroVolo, compagnia, destinazione) VALUES -- --------------------------------------------------------
('AZ202', 'Alitalia', 'Roma'),
('LH404', 'Lufthansa', 'Berlino'), --
('RY123', 'Ryanair Express', 'Londra'), -- Struttura della tabella `prenotazione`
('DL100', 'Delta', 'New York'), --
CREATE TABLE `prenotazione` (
`idPrenotazione` int(11) NOT NULL,
`dataPrenotazione` date NOT NULL,
`prezzo` decimal(10,2) DEFAULT NULL,
`classe` varchar(20) DEFAULT NULL,
`idPassaporto` varchar(20) DEFAULT NULL,
`numeroVolo` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dump dei dati per la tabella `prenotazione`
--
INSERT INTO `prenotazione` (`idPrenotazione`, `dataPrenotazione`, `prezzo`, `classe`, `idPassaporto`, `numeroVolo`) VALUES
(1, '2024-09-01', '45.00', 'Economy', 'AB12345', 'AZ202'),
(2, '2024-10-05', '150.00', 'Business', 'XY98765', 'AZ202'),
(3, '2024-11-12', '1200.00', 'First', 'US55555', 'DL100'),
(4, '2024-09-15', '80.00', 'Economy', 'FR11111', 'AF505'),
(5, '2024-10-20', '60.00', 'Economy', 'DE22222', 'RY123'),
(6, '2024-12-01', '300.00', 'Business', 'ES33333', 'LH404'),
(7, '2024-08-30', '400.00', 'Business', 'AB12345', 'DL100'),
(8, '2024-10-01', '35.00', 'Economy', 'RO99999', 'AZ202');
-- --------------------------------------------------------
--
-- Struttura della tabella `utente`
--
CREATE TABLE `utente` (
`username` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dump dei dati per la tabella `utente`
--
INSERT INTO `utente` (`username`, `email`, `password`) VALUES
('farfabrizio', 'farfabrizio@tiscali.it', '$2y$10$KXjfQOoP2U0kfy06o3Wdf.u0vjGbBQquD/IEf8LxHKVEOnu5OQoDO'),
('cicciopalla', 'cicciopalla@gmail.com', '$2y$10$z3FiR6BoTHKU6lmRzRdIrOwZ3Pgq1V.ngypNgI.wqju2mhSde6odu');
-- --------------------------------------------------------
--
-- Struttura della tabella `volo`
--
CREATE TABLE `volo` (
`numeroVolo` varchar(10) NOT NULL,
`compagnia` varchar(50) NOT NULL,
`destinazione` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dump dei dati per la tabella `volo`
--
INSERT INTO `volo` (`numeroVolo`, `compagnia`, `destinazione`) VALUES
('AF505', 'Air France', 'Parigi'), ('AF505', 'Air France', 'Parigi'),
('GH000', 'Ghost Air', 'Nessun Luogo'); ('AZ202', 'Alitalia', 'Roma'),
('DL100', 'Delta', 'New York'),
('GH000', 'Ghost Air', 'Nessun Luogo'),
('LH404', 'Lufthansa', 'Berlino'),
('RY123', 'Ryanair Express', 'Londra');
INSERT INTO PRENOTAZIONE (dataPrenotazione, prezzo, classe, idPassaporto, numeroVolo) VALUES --
('2024-09-01', 45.00, 'Economy', 'AB12345', 'AZ202'), -- Indici per le tabelle scaricate
('2024-10-05', 150.00, 'Business', 'XY98765', 'AZ202'), --
('2024-11-12', 1200.00, 'First', 'US55555', 'DL100'),
('2024-09-15', 80.00, 'Economy', 'FR11111', 'AF505'),
('2024-10-20', 60.00, 'Economy', 'DE22222', 'RY123'),
('2024-12-01', 300.00, 'Business', 'ES33333', 'LH404'),
('2024-08-30', 400.00, 'Business', 'AB12345', 'DL100'),
('2024-10-01', 35.00, 'Economy', 'RO99999', 'AZ202');
INSERT INTO BAGAGLIO (dataImbarco, peso, smarrito, idPassaporto) VALUES --
('2024-09-01', 15.50, 0, 'AB12345'), -- Indici per le tabelle `bagaglio`
('2024-10-05', 20.00, 0, 'XY98765'), --
('2024-10-05', 10.50, 0, 'XY98765'), ALTER TABLE `bagaglio`
('2024-12-05', 23.00, 0, 'US55555'), ADD PRIMARY KEY (`idBagaglio`),
('2024-12-15', 22.00, 1, 'US55555'), ADD KEY `idPassaporto` (`idPassaporto`);
('2024-12-20', 18.00, 0, 'US55555'),
('2024-12-25', 12.00, 0, 'US55555'), --
('2024-09-15', 19.00, 0, 'FR11111'), -- Indici per le tabelle `passeggero`
('2024-11-30', 25.00, 0, 'CA77777'); --
ALTER TABLE `passeggero`
ADD PRIMARY KEY (`idPassaporto`);
--
-- Indici per le tabelle `prenotazione`
--
ALTER TABLE `prenotazione`
ADD PRIMARY KEY (`idPrenotazione`),
ADD KEY `idPassaporto` (`idPassaporto`),
ADD KEY `numeroVolo` (`numeroVolo`);
--
-- Indici per le tabelle `volo`
--
ALTER TABLE `volo`
ADD PRIMARY KEY (`numeroVolo`);
--
-- AUTO_INCREMENT per le tabelle scaricate
--
--
-- AUTO_INCREMENT per la tabella `bagaglio`
--
ALTER TABLE `bagaglio`
MODIFY `idBagaglio` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
--
-- AUTO_INCREMENT per la tabella `prenotazione`
--
ALTER TABLE `prenotazione`
MODIFY `idPrenotazione` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
--
-- Limiti per le tabelle scaricate
--
--
-- Limiti per la tabella `bagaglio`
--
ALTER TABLE `bagaglio`
ADD CONSTRAINT `bagaglio_ibfk_1` FOREIGN KEY (`idPassaporto`) REFERENCES `passeggero` (`idPassaporto`);
--
-- Limiti per la tabella `prenotazione`
--
ALTER TABLE `prenotazione`
ADD CONSTRAINT `prenotazione_ibfk_1` FOREIGN KEY (`idPassaporto`) REFERENCES `passeggero` (`idPassaporto`),
ADD CONSTRAINT `prenotazione_ibfk_2` FOREIGN KEY (`numeroVolo`) REFERENCES `volo` (`numeroVolo`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+12
View File
@@ -0,0 +1,12 @@
<?php
$host = "localhost";
$user = "root";
$pass = "root";
$db = "aeroporto";
$conn = mysqli_connect($host, $user, $pass, $db);
if (!$conn) {
die("Connessione fallita: " . mysqli_connect_error());
}
?>
+127 -13
View File
@@ -1,27 +1,141 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="it"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gestione aeroporto</title> <title>Document</title>
<link rel="stylesheet" href="style.css">
<style> <style>
.no{ /* Reset e Font */
body {
font-family: 'Segoe UI', Arial, sans-serif;
background-color: #80a9e7;
color: #333;
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 20px;
margin: 0;
}
/* Contenitore per Form e Tabelle */
.box {
background: #fff;
padding: 25px;
border-radius: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 500px;
/* Più stretto per i form */
margin-bottom: 20px;
}
/* Estensione per la tabella (più larga) */
.wide-box {
max-width: 800px;
}
h2 {
margin-top: 0;
color: #1c1e21;
text-align: center; text-align: center;
} }
button{
margin: 10px 10px 10px 10px; /* Stile Input e Bottoni */
width: 350px; input {
width: 100%;
padding: 12px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 6px;
box-sizing: border-box;
/* Importante per il padding */
}
button {
width: 100%;
padding: 12px;
background-color: #007bff;
border: none;
border-radius: 6px;
color: white;
font-weight: bold;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
/* Tabella */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th,
td {
text-align: left;
padding: 12px;
border-bottom: 1px solid #eee;
}
th {
background-color: #f8f9fa;
color: #555;
}
tr:hover {
background-color: #fafafa;
}
/* Link e messaggi */
a {
color: #007bff;
text-decoration: none;
font-size: 14px;
}
a:hover {
text-decoration: underline;
}
.msg {
padding: 10px;
margin-bottom: 15px;
border-radius: 5px;
text-align: center;
font-size: 14px;
}
.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="no">
<h2>Gestione Aeroporto</h2> <center>
<a href="login.php"><button>Login</button></a><br> <h1>Gestione Aeroporto</h1>
<a href="register.php"><button>Registrati</button></a><br> </center>
<a href="https://cdn.mtdv.me/video/rick.mp4"><button>Logout</button></a><br> <!-- Ho rimosso il </center> orfano e corretto i doppi apici -->
<div style="width: 100%; max-width: 300px;">
<button class="btn-1" onclick="window.location.href='login.php'">Login</button><br><br>
<button class="btn-2" onclick="window.location.href='registrati.php'">Registrati</button><br><br>
<button class="btn-3" onclick="window.location.href='logout.php'">Logout</button>
</div> </div>
</body> </body>
</html> </html>
+118 -17
View File
@@ -1,24 +1,125 @@
<?php
// 1. IL PHP SEMPRE IN ALTO (PRIMA DI OGNI HTML/CSS)
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
require '_db_config.php'; // Assicurati che il file si chiami così e che la variabile sia $conn
$messaggio_errore = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// RIMOSSO il controllo su 'email' perché nel form non c'è
if (isset($_POST['username']) && isset($_POST['password'])) {
$user = $_POST['username'];
$pass = $_POST['password'];
// CONTROLLA SE LA TABELLA È 'utente' O 'utenti'
$sql = "SELECT password FROM utente WHERE username = ?";
$stmt = mysqli_prepare($conn, $sql);
if ($stmt) {
mysqli_stmt_bind_param($stmt, "s", $user);
mysqli_stmt_execute($stmt);
$risultato = mysqli_stmt_get_result($stmt);
$riga = mysqli_fetch_assoc($risultato);
if ($riga && password_verify($pass, $riga['password'])) {
$_SESSION['loggato'] = true;
$_SESSION['utente'] = $user;
// Ora il reindirizzamento funzionerà perché non c'è HTML sopra
header("Location: visualizza_dati.php");
exit;
} else {
$messaggio_errore = "Username o Password non validi!";
}
mysqli_stmt_close($stmt);
} else {
$messaggio_errore = "Errore nel database: " . mysqli_error($conn);
}
}
}
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="it"> <html lang="it">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Login</title>
<title>Login - Accesso aeroporto</title> <style>
<link rel="stylesheet" href="style.css"> /* Il tuo CSS qui (lo stesso che hai postato) */
</head> body {
<body> font-family: 'Segoe UI', Arial, sans-serif;
<?php background-color: #f0f2f5;
if(isset($_POST['username']) || isset($_POST['password'])){ display: flex;
echo "PUPPAMI LA FAVA<br><br>"; flex-direction: column;
align-items: center;
padding: 40px;
} }
?>
<form class="form-group" action="" method="POST"> .box {
<h4 style="text-align: center;">Accedi</h4> background: #fff;
<label for="username">Nome utente</label> padding: 25px;
<input type="text" id="username" name="username"> border-radius: 10px;
<label for="password">Password</label> box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
<input type="password" id="password" name="password"> width: 100%;
<input type="submit" value="Accedi"> max-width: 400px;
</form> }
input {
width: 100%;
padding: 12px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 6px;
box-sizing: border-box;
}
button {
width: 100%;
padding: 12px;
background-color: #007bff;
border: none;
border-radius: 6px;
color: white;
font-weight: bold;
cursor: pointer;
}
.error {
background: #f8d7da;
color: #721c24;
padding: 10px;
border-radius: 5px;
margin-bottom: 15px;
text-align: center;
}
</style>
</head>
<body>
<div class="box">
<h2>Accedi</h2>
<!-- Visualizza l'errore se presente -->
<?php if ($messaggio_errore): ?>
<div class="error"><?php echo $messaggio_errore; ?></div>
<?php endif; ?>
<form method="post" action="login.php">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Accedi</button>
</form>
<p style="text-align:center; margin-top:15px;">
<a href="index.php" style="color:#007bff; text-decoration:none;">Torna alla Home</a>
</p>
</div>
</body> </body>
</html> </html>
+6
View File
@@ -0,0 +1,6 @@
<?php
session_start();
session_unset();
session_destroy();
header("Location: index.php");
exit;
-28
View File
@@ -1,28 +0,0 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registrazione - Gestione aeroporto</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
echo "PUPPAMI LA FAVA<br><br>";
}
?>
<form class="form-group" action="" method="POST">
<h4 style="text-align: center;">Registrati</h4>
<label for="username">Nome utente</label>
<input type="text" id="username" name="username">
<label for="email">Indirizzo e-mail</label>
<input type="email" id="email" name="email">
<label for="password">Password</label>
<input type="password" id="password" name="password">
<label for="passwordConfirm">Conferma password</label>
<input type="password" id="passwordConfirm" name="passwordConfirm">
<input type="submit" value="Registrati">
</form>
</body>
</html>
+162
View File
@@ -0,0 +1,162 @@
<head>
<style>
/* Reset e Font */
body {
font-family: 'Segoe UI', Arial, sans-serif;
background-color: #f0f2f5;
color: #333;
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 20px;
margin: 0;
}
/* Contenitore per Form e Tabelle */
.box {
background: #fff;
padding: 25px;
border-radius: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 500px;
/* Più stretto per i form */
margin-bottom: 20px;
}
/* Estensione per la tabella (più larga) */
.wide-box {
max-width: 800px;
}
h2 {
margin-top: 0;
color: #1c1e21;
text-align: center;
}
/* Stile Input e Bottoni */
input {
width: 100%;
padding: 12px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 6px;
box-sizing: border-box;
/* Importante per il padding */
}
button {
width: 100%;
padding: 12px;
background-color: #007bff;
border: none;
border-radius: 6px;
color: white;
font-weight: bold;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
/* Tabella */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th,
td {
text-align: left;
padding: 12px;
border-bottom: 1px solid #eee;
}
th {
background-color: #f8f9fa;
color: #555;
}
tr:hover {
background-color: #fafafa;
}
/* Link e messaggi */
a {
color: #007bff;
text-decoration: none;
font-size: 14px;
}
a:hover {
text-decoration: underline;
}
.msg {
padding: 10px;
margin-bottom: 15px;
border-radius: 5px;
text-align: center;
font-size: 14px;
}
.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
</style>
</head>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once '_db_config.php';
if (($_SERVER['REQUEST_METHOD'] ?? '') == 'POST') {
if (isset($_POST['username']) && isset($_POST['email']) && isset($_POST['password'])) {
$user = $_POST['username'];
$email = $_POST['email'];
$pass = password_hash($_POST['password'], PASSWORD_DEFAULT);
// 1. Prepariamo la query
$sql = "INSERT INTO utente (username, email, password) VALUES (?, ?, ?)";
$stmt = mysqli_prepare($conn, $sql);
// 2. Colleghiamo i parametri (sss = 3 stringhe)
mysqli_stmt_bind_param($stmt, "sss", $user, $email, $pass);
// 3. Eseguiamo lo statement
if (mysqli_stmt_execute($stmt)) {
echo "Registrazione avvenuta! <a href='login.php'>Accedi qui</a>";
} else {
echo "Errore nell'inserimento: " . mysqli_error($conn);
}
}
// 4. Chiudiamo lo statement
mysqli_stmt_close($stmt);
}
?>
<form action="" method="post">
<input type="text" name="username" placeholder="Username" required><br>
<input type="email" name="email" placeholder="Email" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<button type="submit">Registrati</button>
</form>
+152
View File
@@ -0,0 +1,152 @@
<head>
<style>
/* Reset e Font */
body {
font-family: 'Segoe UI', Arial, sans-serif;
background-color: #f0f2f5;
color: #333;
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 20px;
margin: 0;
}
/* Contenitore per Form e Tabelle */
.box {
background: #fff;
padding: 25px;
border-radius: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 500px;
/* Più stretto per i form */
margin-bottom: 20px;
}
/* Estensione per la tabella (più larga) */
.wide-box {
max-width: 800px;
}
h2 {
margin-top: 0;
color: #1c1e21;
text-align: center;
}
/* Stile Input e Bottoni */
input {
width: 100%;
padding: 12px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 6px;
box-sizing: border-box;
/* Importante per il padding */
}
button {
width: 100%;
padding: 12px;
background-color: #007bff;
border: none;
border-radius: 6px;
color: white;
font-weight: bold;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
/* Tabella */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th,
td {
text-align: left;
padding: 12px;
border-bottom: 1px solid #eee;
}
th {
background-color: #f8f9fa;
color: #555;
}
tr:hover {
background-color: #fafafa;
}
/* Link e messaggi */
a {
color: #007bff;
text-decoration: none;
font-size: 14px;
}
a:hover {
text-decoration: underline;
}
.msg {
padding: 10px;
margin-bottom: 15px;
border-radius: 5px;
text-align: center;
font-size: 14px;
}
.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
</style>
</head>
<?php
session_start();
require '_db_config.php';
// Se la sessione non è attiva, torna al login
if (!isset($_SESSION['loggato'])) {
header("Location: login.php");
exit;
}
// Query semplice (senza parametri esterni non serve il prepared statement)
$sql = "SELECT username, email FROM utente";
$query_risultato = mysqli_query($conn, $sql);
?>
<h2>Benvenuto, <?php echo htmlspecialchars($_SESSION['utente']); ?></h2>
<a href="logout.php">Disconnetti</a>
<table border="1" style="width:100%; margin-top:20px; text-align:left;">
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
</tr>
<?php while ($riga = mysqli_fetch_assoc($query_risultato)): ?>
<tr>
<td><?php echo $riga['id']; ?></td>
<td><?php echo htmlspecialchars($riga['username']); ?></td>
<td><?php echo htmlspecialchars($riga['email']); ?></td>
</tr>
<?php endwhile; ?>
</table>