Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = "localhost";
- $db_user = "root";
- $db_psw = "root";
- $db_name = "biblioteca";
- $mysqli = new mysqli($host, $db_user, $db_psw);
- if ($mysqli ->connect_error){
- die('Errore di connessione '.$mysqli->connect_errno.' '.$mysqli->connect_error);
- }
- //controllo se il db esiste
- if(!$mysqli->query('CREATE DATABASE '.$db_name))
- {
- echo "Query failed: \n".$mysqli->error;
- }
- $mysqli->query("USE ".$db_name);
- //creazione della tabella per gli utenti
- $string_query = "CREATE TABLE utenti (
- id INT(5) NOT NULL AUTO_INCREMENT,
- user VARCHAR(40) NOT NULL,
- pass VARCHAR(64) NOT NULL,
- nome VARCHAR(30) NOT NULL,
- cognome VARCHAR(30) NOT NULL,
- indirizzo TEXT NOT NULL,
- nascita DATE NOT NULL,
- PRIMARY KEY (id))";
- if(!$res = $mysqli->query($string_query))
- echo"query failed \n".$mysqli->error;
- else
- echo"Tabella utenti creata($res)\n";
- //tabella books
- $string_query_books = "CREATE TABLE books (
- id INT(5) NOT NULL AUTO_INCREMENT,
- autore VARCHAR(40) NOT NULL,
- titolo TEXT NOT NULL,
- editore VARCHAR(40) NOT NULL,
- anno SMALLINT(2) NOT NULL,
- PRIMARY KEY (id))";
- if(!$res = $mysqli->query($string_query_books))
- echo"query failed \n".$mysqli->error;
- else
- echo"Tabella utenti creata($res)\n";
- //tabella prestiti
- $string_query_loan = "CREATE TABLE loan (
- id INT NOT NULL AUTO_INCREMENT,
- id_utente INT NOT NULL,
- id_libro TEXT NOT NULL,
- data DATE NOT NULL,
- restituito ENUM('0','1') NOT NULL,
- PRIMARY KEY (id))";
- if(!$res = $mysqli->query($string_query_loan))
- echo"query failed \n".$mysqli->error;
- else
- echo"Tabella utenti creata($res)\n";
- $password = sha1("password");
- /*$query_add_utenti = "INSERT INTO utenti (`id`,`user`,`pass`,`nome`,`cognome`,`indirizzo`,`nascita`)
- VALUES (NULL, 'giuseppe.grasso', '$password','Giuseppe' ,'Grasso', 'Viale delle province 12','2019-10-16')";
- if(!$res = $mysqli->query($query_add_utenti))
- echo"query failed \n".$mysqli->error;
- else
- echo "\n";
- echo"Utente inserito($res)\n";
- echo"Righe generate: ".$mysqli->affected_rows."<br />";
- echo"Ultimo ID inserito: ".$mysqli->insert_id."<br />";
- */
- $user = "giuseppe.grasso";
- $query = $mysqli->query("SELECT * FROM utenti WHERE user = '$user' AND pass = '$password'");
- if($query->num_rows){
- //echo "accesso consentito! \n";
- print_r($query->fetch_all(MYSQLI_BOTH));
- }else {
- echo "accesso negato! \n";
- }
- $mysqli->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement