Grazie per il consiglio.
Seguendo le indicazioni ho provato ad elaborare questo codice che però non funziona.
Innanzitutto ho creato la funzione javascript:
var nome = document.getElementById("nome").value;
var mail = document.getElementById("mail").value;
xmlHttp.open('GET', 'request.php?mail='+mail+'&nome='+nome, true);
xmlHttp.onreadystatechange = stateChanged;
var risp=xmlHttp.responseText;
xmlHttp.send(null);
if (risp=='true')
{
alert("Utente già presente: non c'è corrispondenza tra e-mail e nick");
return false;
}
Il file request.php è così strutturato:
Codice PHP:
<?php
include ("funzioni.php");
$db=connessione();
$mail=$_GET['mail'];
$nome=$_GET['nome'];
$sql="SELECT * FROM autori WHERE mail='$mail'";
$s = $db->query($sql)or die("Errore ".$db->error);
$nRighe = $s->num_rows;
if ($nRighe != 0)
{
$sql="SELECT * from autori WHERE mail='$mail' and nome='$nome'";
$t = $db->query($sql)or die("Errore ".$db->error);
$n = $t->num_rows;
if ($n == 0)
{
$out='true';
}
}
echo $out;
?>