Advertisement
Guest User

Untitled

a guest
May 26th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. <?PHP
  2. // variabili di connessione
  3. // nome server, nome utente,
  4. // Password, nomedatabase, tabella
  5. $ServerName = "localhost";
  6. $UserName = "root";
  7. $Password = "madara";
  8. $DbName = "EP";
  9. $tbl_name="studente";
  10.  
  11. // la connessione al database e alla tabella
  12. $conn = mysql_connect($ServerName, $UserName, $Password)
  13. or die("CONNECTION NON RIUSCITA");
  14. mysql_select_db($DbName, $conn);
  15. $nome = $_POST["nome"];
  16. $cognome = $_POST["cognome"];
  17. $universita=$_POST['universita'];
  18. $username = $_POST["username"];
  19. $password = $_POST["password"];
  20. $conferma=$_POST['conferma'];
  21. $email = $_POST["email"];
  22. $universita = $_POST["universita"];
  23.  
  24.  
  25.  
  26. //Verifico il valore di $nome;
  27. if(chkEmail($email)) {
  28. if( isset($password) and isset($conferma) ){
  29. if( $password!=$conferma ) echo"ricontrolla i campi password";
  30. else{
  31. if( !isset($nome) or !isset($cognome) or !isset($username) )
  32. echo"<center>tutti i campi sono obbligatori</center>";
  33. else{
  34. if($universita=="Salerno" or $universita=="Londra"){
  35. $query="Insert into `$tb1_name` (`nome`,`cognome`,`user_name`,`password`,'universita') VALUES ('$nome','$cognome','$username','$password','$universita')";
  36. $result=mysql_query($query,$connessione); // result ci serve x fare il controllo
  37. mysql_close($conn);
  38. if ($result) die("errore registrazione");
  39. else echo "<center>"+$nome ." ti sei iscritto, ora sei riconosciuto come ".$username+"</center>";
  40. }
  41. else{
  42. echo"<center>Spiacente la tua universit&agrave non fa parte del progetto European Platform </center>";
  43. }
  44. }
  45. }
  46. }
  47. }
  48. else{
  49. echo"<center>campi password non inseriti correttamente</center>";
  50. }
  51.  
  52.  
  53.  
  54. ?>
  55. <?php
  56.  
  57. function chkEmail($email)
  58. {
  59. // elimino spazi, "a capo" e altro alle estremità della stringa
  60. $email = trim($email);
  61. // se la stringa è vuota sicuramente non è una mail
  62. if(!$email) {
  63. return false;
  64. }
  65. // controllo che ci sia una sola @ nella stringa
  66. $num_at = count(explode( '@', $email )) - 1;
  67. if($num_at != 1) {
  68. return false;
  69. }
  70. // controllo la presenza di ulteriori caratteri "pericolosi":
  71. if(strpos($email,';') || strpos($email,',') || strpos($email,' ')) {
  72. return false;
  73. }
  74. // la stringa rispetta il formato classico di una mail?
  75. if(!preg_match( '/^[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}$/', $email)) {
  76. return false;
  77. }
  78. return true;
  79. }
  80.  
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement