ragazzi ho la necessita di dove gestire 3 query diverse a seconda del valore tipologia che ricevo in post..allora finché fa il controllo dove il valore e uguale a 1 cioè privato ok se metto azienda cioè 2 si inchioda vi posto i due script:
login.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="md5.js" type="text/javascript"></script>
<script type="text/javascript">
function criptazione_pass_login(){ var ie43 = (document.all) ? true : false; var ns43 = (document.layers) ? true : false; var ns63 = (document.getElementById && !document.all) ? true : false; if (ie43) {myform_login=document.all['form_login'];} if (ns43) {myform_login=document.layers['form_login'];} if (ns63) {myform_login=document.getElementById('form_login');} login_access(); }
</script>
<script>
var time_variable;function getXMLObject() {var xmlHttp = false;try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") }catch (e) {try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e2) {
xmlHttp = false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
}
var xmlhttp= new getXMLObject();
function login_access() {
var getdate = new Date();
if(xmlhttp) {
document.getElementById('load_login').innerHTML =" <img src=\"loading.gif\" alt=\"loading\"></img>";
var email = document.getElementById('email_login1').value;
var pass = document.getElementById('password_nascosta_login').value;
var tipologia = document.getElementById('tipologia_login').value;
var parameters="email="+email+"&pass="+pass+"&tipologia="+tipologia
xmlhttp.open("POST","login.php",true);
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(parameters);
}
}
function handleServerResponse() {
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
if(xmlhttp.responseText=="1"){
document.getElementById('load_login').innerHTML ="errore login";
}
else if(xmlhttp.responseText=="0"){
document.getElementById('load_login').innerHTML ="ok";
window.location="utente.php";
}
}else if(xmlhttp.responseText=="2"){
document.getElementById('load_login').innerHTML ="ok";
window.location="az.php";
} else{
document.getElementById('load_login').innerHTML ="errore login";
}
}
}
</script>
</head>
<body>
<form action="" method="post" name="form_login">
email:<input type="text" id="email_login1" name="email_login"/>
password:<input type="password" id="pass" name="password_login" />
<input type="hidden" name="hash_login" id="password_nascosta_login" size="10">
<label>
<select name="tipologia_login" id="tipologia_login">
<option value="1">Privato</option>
<option value="2">Azienda</option>
<option value="Ente">Ente</option>
</select>
</label>
<input type="button" value="login" onclick="hash_login.value = hex_md5(password_login.value);criptazione_pass_login();" />
<div id="load_login"></div>
</form>
</body>
</html>
ora login.php
<?php
$email=$_POST['email'];
$pass=$_POST['pass'];
$tipologia=$_POST['tipologia'];
$conn=mysql_connect("localhost","****","***");
if(!$conn)
{
echo"IMPOSSIBILE CONNETTERSI";
exit();
}
$db=mysql_select_db("hellocom_hello");
if(!$db)
{
echo"IMPOSSIBILE APRIRE DATABASE";
exit();
}
if($tipologia==1){
$dati="SELECT id FROM registrazione_utente where password_md5 = '$pass' AND email = '$email'";
$res=mysql_query($dati);
if(!$res){
echo"no";
}
$num_rows = mysql_num_rows($res);
if($num_rows==true){
setcookie("email", $email, time()+3600);
setcookie("password", $pass, time()+3600);
echo "0";
}else{
echo"1";
}
}elseif($tipologia==2){
$dati1="SELECT id FROM registrazione_azienda where password_azienda_md5 = '$pass' AND email_azienda = '$email'";
$res1=mysql_query($dati1);
if(!$res1){
echo"no";
}
$num_rows1 = mysql_num_rows($res1);
if($num_rows1==true){
setcookie("email1", $email, time()+3600);
setcookie("password1", $pass, time()+3600);
echo "2";
}else{
echo"3";
}
}
?>
login.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="md5.js" type="text/javascript"></script>
<script type="text/javascript">
function criptazione_pass_login(){ var ie43 = (document.all) ? true : false; var ns43 = (document.layers) ? true : false; var ns63 = (document.getElementById && !document.all) ? true : false; if (ie43) {myform_login=document.all['form_login'];} if (ns43) {myform_login=document.layers['form_login'];} if (ns63) {myform_login=document.getElementById('form_login');} login_access(); }
</script>
<script>
var time_variable;function getXMLObject() {var xmlHttp = false;try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") }catch (e) {try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e2) {
xmlHttp = false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
}
var xmlhttp= new getXMLObject();
function login_access() {
var getdate = new Date();
if(xmlhttp) {
document.getElementById('load_login').innerHTML =" <img src=\"loading.gif\" alt=\"loading\"></img>";
var email = document.getElementById('email_login1').value;
var pass = document.getElementById('password_nascosta_login').value;
var tipologia = document.getElementById('tipologia_login').value;
var parameters="email="+email+"&pass="+pass+"&tipologia="+tipologia
xmlhttp.open("POST","login.php",true);
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(parameters);
}
}
function handleServerResponse() {
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
if(xmlhttp.responseText=="1"){
document.getElementById('load_login').innerHTML ="errore login";
}
else if(xmlhttp.responseText=="0"){
document.getElementById('load_login').innerHTML ="ok";
window.location="utente.php";
}
}else if(xmlhttp.responseText=="2"){
document.getElementById('load_login').innerHTML ="ok";
window.location="az.php";
} else{
document.getElementById('load_login').innerHTML ="errore login";
}
}
}
</script>
</head>
<body>
<form action="" method="post" name="form_login">
email:<input type="text" id="email_login1" name="email_login"/>
password:<input type="password" id="pass" name="password_login" />
<input type="hidden" name="hash_login" id="password_nascosta_login" size="10">
<label>
<select name="tipologia_login" id="tipologia_login">
<option value="1">Privato</option>
<option value="2">Azienda</option>
<option value="Ente">Ente</option>
</select>
</label>
<input type="button" value="login" onclick="hash_login.value = hex_md5(password_login.value);criptazione_pass_login();" />
<div id="load_login"></div>
</form>
</body>
</html>
ora login.php
<?php
$email=$_POST['email'];
$pass=$_POST['pass'];
$tipologia=$_POST['tipologia'];
$conn=mysql_connect("localhost","****","***");
if(!$conn)
{
echo"IMPOSSIBILE CONNETTERSI";
exit();
}
$db=mysql_select_db("hellocom_hello");
if(!$db)
{
echo"IMPOSSIBILE APRIRE DATABASE";
exit();
}
if($tipologia==1){
$dati="SELECT id FROM registrazione_utente where password_md5 = '$pass' AND email = '$email'";
$res=mysql_query($dati);
if(!$res){
echo"no";
}
$num_rows = mysql_num_rows($res);
if($num_rows==true){
setcookie("email", $email, time()+3600);
setcookie("password", $pass, time()+3600);
echo "0";
}else{
echo"1";
}
}elseif($tipologia==2){
$dati1="SELECT id FROM registrazione_azienda where password_azienda_md5 = '$pass' AND email_azienda = '$email'";
$res1=mysql_query($dati1);
if(!$res1){
echo"no";
}
$num_rows1 = mysql_num_rows($res1);
if($num_rows1==true){
setcookie("email1", $email, time()+3600);
setcookie("password1", $pass, time()+3600);
echo "2";
}else{
echo"3";
}
}
?>