Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- // variabili di connessione
- // nome server, nome utente,
- // Password, nomedatabase, tabella
- $ServerName = "localhost";
- $UserName = "root";
- $Password = "madara";
- $DbName = "EP";
- $tbl_name="studente";
- // la connessione al database e alla tabella
- $conn = mysql_connect($ServerName, $UserName, $Password)
- or die("CONNECTION NON RIUSCITA");
- mysql_select_db($DbName, $conn);
- $nome = $_POST["nome"];
- $cognome = $_POST["cognome"];
- $universita=$_POST['universita'];
- $username = $_POST["username"];
- $password = $_POST["password"];
- $conferma=$_POST['conferma'];
- $email = $_POST["email"];
- $universita = $_POST["universita"];
- //Verifico il valore di $nome;
- if(chkEmail($email)) {
- if( isset($password) and isset($conferma) ){
- if( $password!=$conferma ) echo"ricontrolla i campi password";
- else{
- if( !isset($nome) or !isset($cognome) or !isset($username) )
- echo"<center>tutti i campi sono obbligatori</center>";
- else{
- if($universita=="Salerno" or $universita=="Londra"){
- $query="Insert into `$tb1_name` (`nome`,`cognome`,`user_name`,`password`,'universita') VALUES ('$nome','$cognome','$username','$password','$universita')";
- $result=mysql_query($query,$connessione); // result ci serve x fare il controllo
- mysql_close($conn);
- if ($result) die("errore registrazione");
- else echo "<center>"+$nome ." ti sei iscritto, ora sei riconosciuto come ".$username+"</center>";
- }
- else{
- echo"<center>Spiacente la tua università non fa parte del progetto European Platform </center>";
- }
- }
- }
- }
- }
- else{
- echo"<center>campi password non inseriti correttamente</center>";
- }
- ?>
- <?php
- function chkEmail($email)
- {
- // elimino spazi, "a capo" e altro alle estremità della stringa
- $email = trim($email);
- // se la stringa è vuota sicuramente non è una mail
- if(!$email) {
- return false;
- }
- // controllo che ci sia una sola @ nella stringa
- $num_at = count(explode( '@', $email )) - 1;
- if($num_at != 1) {
- return false;
- }
- // controllo la presenza di ulteriori caratteri "pericolosi":
- if(strpos($email,';') || strpos($email,',') || strpos($email,' ')) {
- return false;
- }
- // la stringa rispetta il formato classico di una mail?
- if(!preg_match( '/^[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}$/', $email)) {
- return false;
- }
- return true;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement