Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(!isset($_SESSION["user"])) {
- header("Location: login.php");
- }
- //validazione campi
- $formato_campi = array(
- 'password' => "/^[\w\W\s]+$/",
- 'nome' => "/^[a-zA-Z' ]{1,}$/",
- 'cognome' => "/^[a-zA-Z' ]{1,}$/",
- 'comune_nascita' => "/^[a-zA-Z' ]{1,}$/",
- 'codice_fiscale' =>"/^[A-Za-z]{6}[A-Za-z0-9]{2}[A-Za-z][A-Za-z0-9]{2}[A-Za-z][A-Za-z0-9]{3}[A-Za-z]$/"
- );
- $link = mysqli_connect('localhost', 'root', '', 'colabufalo') or die('Attenzione, errore in fase di connessione al DB: '.mysqli_connect_error($link));
- mysqli_set_charset($link, 'utf8');
- $sql = " SELECT * FROM soci WHERE user = '$_SESSION[user]'";
- $result = mysqli_query($link, $sql) or die('Attenzione, errore in fase di inserimento dati: '.mysqli_error($link));
- $row = mysqli_fetch_assoc($result);
- // var_dump($row);
- //
- $date1 = explode('-', $_POST['data_nascita']);
- $valido = true;
- // var_dump($_POST['user'], $_POST['password'], $_POST['nome'], $_POST['cognome'], $_POST['data_nascita'], $_POST['codice_fiscale'] );
- //validazione form
- foreach ($formato_campi as $campo => $pattern) {
- if (!isset($_POST[$campo]) || trim($_POST[$campo]) == '') {
- echo "Inserire $campo <br><br>";
- $valido = false;
- } elseif (!(preg_match($pattern, $_POST[$campo]))) {
- echo "Il valore per '$campo' non è valido <br><br>";
- $valido = false;
- }
- }
- // CONTROLLO USER UNIVOCO
- $user = $_POST['user'];
- $query = $link->prepare("SELECT user FROM soci WHERE user = '$_POST[user]'");
- $query->execute();
- $query->store_result();
- $rows = $query->num_rows;
- //
- //
- if ($rows > 1) {
- echo 'Attenzione, email già in uso';
- $valido = false;
- }
- else {
- $valido = true;
- }
- // mysqli_close($link);
- //FINE CONTROLLO USER
- if (!isset($_POST['data_nascita']) || $_POST['data_nascita'] == '' || !checkdate($date1[1], $date1[2], $date1[0])) {
- echo 'Attenzione, inserire una data valida: aaaa-mm-gg';
- $valido = false;
- }
- //update database
- if($valido) {
- $nome = mysqli_real_escape_string($link, $_POST['nome']);
- $cognome = mysqli_real_escape_string($link, $_POST['cognome']);
- $comune_nascita = mysqli_real_escape_string($link, $_POST['comune_nascita']);
- $password = $_POST['password'];
- $query = $link->prepare(" SELECT password FROM soci WHERE id = '$row[id]' AND password = '$password' ");
- $query->execute();
- $query->store_result();
- $rows = $query->num_rows;
- if ($rows = 1) {
- $sql = "UPDATE soci
- SET user = '$_POST[user]',
- nome = '$nome',
- cognome = '$cognome',
- data_nascita = '$_POST[data_nascita]',
- comune_nascita = '$comune_nascita',
- codice_fiscale = '$_POST[codice_fiscale]'
- WHERE id = '$row[id]'";
- $result = mysqli_query($link, $sql)
- or die( "Attenzione! Errore in fase di inserimento dati: " . mysqli_error($link) );
- mysqli_close($link);
- header("Location: pagina-personale.php");
- }
- else{
- $sql = "UPDATE soci
- SET user = '$_POST[user]',
- password = md5('$_POST[password]'),
- nome = '$nome',
- cognome = '$cognome',
- data_nascita = '$_POST[data_nascita]',
- comune_nascita = '$comune_nascita',
- codice_fiscale = '$_POST[codice_fiscale]'
- WHERE id = '$row[id]'";
- $result = mysqli_query($link, $sql)
- or die( "Attenzione! Errore in fase di inserimento dati: " . mysqli_error($link) );
- mysqli_close($link);
- header("Location: pagina-personale.php");
- }
- }
- ?>
Add Comment
Please, Sign In to add comment