Advertisement
Guest User

Untitled

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