//dati form
$citta = $_POST['citta'];
$tel1 = $_POST['tel1'];
$tel2 = $_POST['tel2'];
$email = $_POST['email'];
$nomearray = array(1 => 'nome1','nome2','nome3','nome4','nome5','nome6','nome7','nome8','nome9','nome10','nome11','nome12','nome13',
'nome14','nome15');
foreach ($_POST as $nome => $arraynome) {
$_POST[$nome] = addslashes(stripslashes($arraynome));
}
//connessione e invio al DB
$connessione = mysql_connect($host,$username,$password) or die("Connessione DB fallita");
mysql_select_db($database,$connessione) or die("Selezione DB fallita");
//controlli
$cercasq = "SELECT * FROM $tabella WHERE citta='$citta'";
$risultatosq = mysql_query($cercasq,$connessione);
$rigasq =mysql_num_rows($risultatosq);
if ($rigasq>0){
while($resrowsq = mysql_fetch_row($risultatosq))
{
$citta= addslashes($resrowsq[1]);
echo "la citta " .$citta. " è già presente nel database<br />";
}
} else {
if ($nome1 =='' OR $nome2 =='' OR $nome3 =='' OR $nome4 =='' OR $nome5 =='' OR $nome6 =='' OR $nome7 ==''){
echo "Devi inserire almeno 7 giocatori<br>";
} else {
//inserisci i dati del form
$caricasquadre = "INSERT INTO $tabella (id,citta,tel1,tel2,email) VALUES('','$citta','$tel1','$tel2','$email')";
mysql_query($caricasquadre) or die("Errore...\n<br />Query: " . $caricasquadre . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "citta inserita correttamente!<br>";
$cerca1 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome1%' ";
$risultato1 = mysql_query($cerca1, $connessione);
$riga1 = mysql_num_rows($risultato1);
if ($riga1 > 0) {
echo "il giocatore " . $nome1 . " è già presente nel database<br />";
} else {
$caricagiocatore1 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome1','$citta','','','')";
mysql_query($caricagiocatore1) or die("Errore...\n<br />Query: " . $caricagiocatore1 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome1 inserito correttamente!<br>";
}
$cerca2 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome2%' ";
$risultato2 = mysql_query($cerca2, $connessione);
$riga2 = mysql_num_rows($risultato2);
if ($riga2 > 0) {
echo "il giocatore " . $nome2 . " è già presente nel database<br />";
} else {
$caricagiocatore2 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome2','$citta','','','')";
mysql_query($caricagiocatore2) or die("Errore...\n<br />Query: " . $caricagiocatore2 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome2 inserito correttamente!<br>";
}
$cerca3 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome3%' ";
$risultato3 = mysql_query($cerca3, $connessione);
$riga3 = mysql_num_rows($risultato3);
if ($riga3 > 0) {
echo "il giocatore " . $nome3 . " è già presente nel database<br />";
} else {
$caricagiocatore3 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome3','$citta','','','')";
mysql_query($caricagiocatore3) or die("Errore...\n<br />Query: " . $caricagiocatore3 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome3 inserito correttamente!<br>";
}
$cerca4 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome4%' ";
$risultato4 = mysql_query($cerca4, $connessione);
$riga4 = mysql_num_rows($risultato4);
if ($riga4 > 0) {
echo "il giocatore " . $nome4 . " è già presente nel database<br />";
} else {
$caricagiocatore4 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome4','$citta','','','')";
mysql_query($caricagiocatore4) or die("Errore...\n<br />Query: " . $caricagiocatore4 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome4 inserito correttamente!<br>";
}
$cerca5 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome5%' ";
$risultato5 = mysql_query($cerca5, $connessione);
$riga5 = mysql_num_rows($risultato5);
if ($riga5 > 0) {
echo "il giocatore " . $nome5 . " è già presente nel database<br />";
} else {
$caricagiocatore5 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome5','$citta','','','')";
mysql_query($caricagiocatore5) or die("Errore...\n<br />Query: " . $caricagiocatore5 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome5 inserito correttamente!<br>";
}
$cerca6 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome6%' ";
$risultato6 = mysql_query($cerca6, $connessione);
$riga6 = mysql_num_rows($risultato6);
if ($riga6 > 0) {
echo "il giocatore " . $nome6 . " è già presente nel database<br />";
} else {
$caricagiocatore6 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome6','$citta','','','')";
mysql_query($caricagiocatore6) or die("Errore...\n<br />Query: " . $caricagiocatore6 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome6 inserito correttamente!<br>";
}
$cerca7 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome7%' ";
$risultato7 = mysql_query($cerca7, $connessione);
$riga7 = mysql_num_rows($risultato7);
if ($riga7 > 0) {
echo "il giocatore " . $nome7 . " è già presente nel database<br />";
} else {
$caricagiocatore7 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome7','$citta','','','')";
mysql_query($caricagiocatore7) or die("Errore...\n<br />Query: " . $caricagiocatore7 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome7 inserito correttamente!<br>";
}
if ($nome8 !='') {
$caricagiocatore8 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome8','$citta','','','')";
mysql_query($caricagiocatore8) or die("Errore...\n<br />Query: " . $caricagiocatore8 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome8 inserito correttamente!<br>";
$cerca8 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome8%' ";
$risultato8 = mysql_query($cerca8, $connessione);
$riga8 = mysql_num_rows($risultato8);
if ($riga8 > 0) {
echo "il giocatore " . $nome8 . " è già presente nel database<br />";}}
if ($nome9 !='') {
$caricagiocatore9 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome9','$citta','','','')";
mysql_query($caricagiocatore9) or die("Errore...\n<br />Query: " . $caricagiocatore9 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome9 inserito correttamente!<br>";
$cerca9 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome9%' ";
$risultato9 = mysql_query($cerca9, $connessione);
$riga9 = mysql_num_rows($risultato9);
if ($riga9 > 0) {
echo "il giocatore " . $nome9 . " è già presente nel database<br />";}}
if ($nome10 !='') {
$caricagiocatore10 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome10','$citta','','','')";
mysql_query($caricagiocatore10) or die("Errore...\n<br />Query: " . $caricagiocatore10 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome10 inserito correttamente!<br>";
$cerca10 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome10%' ";
$risultato10 = mysql_query($cerca10, $connessione);
$riga10 = mysql_num_rows($risultato10);
if ($riga10 > 0) {
echo "il giocatore " . $nome10 . " è già presente nel database<br />";}}
if ($nome11 !='') {
$caricagiocatore11 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome11','$citta','','','')";
mysql_query($caricagiocatore11) or die("Errore...\n<br />Query: " . $caricagiocatore11 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome11 inserito correttamente!<br>";
$cerca11 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome11%' ";
$risultato11 = mysql_query($cerca11, $connessione);
$riga11 = mysql_num_rows($risultato11);
if ($riga11 > 0) {
echo "il giocatore " . $nome11 . " è già presente nel database<br />";}}
if ($nome12 !='') {
$caricagiocatore12 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome12','$citta','','','')";
mysql_query($caricagiocatore12) or die("Errore...\n<br />Query: " . $caricagiocatore12 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome12 inserito correttamente!<br>";
$cerca12 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome12%' ";
$risultato12 = mysql_query($cerca12, $connessione);
$riga12 = mysql_num_rows($risultato12);
if ($riga12 > 0) {
echo "il giocatore " . $nome12 . " è già presente nel database<br />";}}
if ($nome13 !='') {
$caricagiocatore13 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome13','$citta','','','')";
mysql_query($caricagiocatore13) or die("Errore...\n<br />Query: " . $caricagiocatore13 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome13 inserito correttamente!<br>";
$cerca13 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome13%' ";
$risultato13 = mysql_query($cerca13, $connessione);
$riga13 = mysql_num_rows($risultato13);
if ($riga13 > 0) {
echo "il giocatore " . $nome13 . " è già presente nel database<br />";}}
if ($nome14 !='') {
$caricagiocatore14 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome14','$citta','','','')";
mysql_query($caricagiocatore14) or die("Errore...\n<br />Query: " . $caricagiocatore14 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome14 inserito correttamente!<br>";
$cerca14 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome14%' ";
$risultato14 = mysql_query($cerca14, $connessione);
$riga14 = mysql_num_rows($risultato14);
if ($riga14 > 0) {
echo "il giocatore " . $nome14 . " è già presente nel database<br />";}}
if ($nome15 !='') {
$caricagiocatore15 = "INSERT INTO $tabella2 (id, nome, citta, eta, via, cap) VALUES ('','$nome15','$citta','','','')";
mysql_query($caricagiocatore15) or die("Errore...\n<br />Query: " . $caricagiocatore15 . "<br />\nDettagli: (" . mysql_errno() . ") " . mysql_error());
echo "giocatore $nome15 inserito correttamente!<br>";
$cerca15 = "SELECT nome FROM $tabella2 WHERE nome LIKE '%$nome15%' ";
$risultato15 = mysql_query($cerca15, $connessione);
$riga15 = mysql_num_rows($risultato15);
if ($riga15 > 0) {
echo "il giocatore " . $nome15 . " è già presente nel database<br />";}}
}
}