-
Salve, ho scritto la pagina login. con alcune delle mie funzioni.
Ma volevo solo sapere come faccio ad dirgli se non esiste quell'email o password dentro il db far venire fuori un messaggio del tipo "Non esistono" Mi dite come fare?.grazie.
ecco il codice:
<!-- #include virtual="/inc.asp" --> <!-- #include virtual="/header.asp" --> <% function TestCaptcha(byval valSession, byval valCaptcha) dim tmpSession valSession = Trim(valSession) valCaptcha = Trim(valCaptcha) if (valSession = vbNullString) or (valCaptcha = vbNullString) then TestCaptcha = false else tmpSession = valSession valSession = Trim(Session(valSession)) Session(tmpSession) = vbNullString if valSession = vbNullString then TestCaptcha = false else valCaptcha = Replace(valCaptcha,"i","I") if StrComp(valSession,valCaptcha,1) = 0 then TestCaptcha = true else TestCaptcha = false end if end if end if end function %><% action = Request.Form("act") email=Request.Form("email") loginpassword=Request.Form("password") %> <% errore = "" if action ="entra" then if email = "" then errore = errore & "Non hai inserito l'email" elseif loginpassword = "" then errore = errore & "Non hai inserito la password" Elseif not IsEmpty(Request.Form("invia")) then if TestCaptcha("ASPCAPTCHA", Request.Form("captchacode")) then 'errore = errore & "Devi inserire password per modificare i dati" SQL = "SELECT * FROM users WHERE email = '" & email & "' and passwords = '" & loginpassword & "' and locks='2';" Set oRs = Mysql_Rows(oCn,SQL) if not oRs.eof then SQL = "SELECT * FROM users WHERE email = '" & email & "' and passwords = '" & loginpassword & "' and locks='2';" Set RS = MySql_Rows(oCn, SQL) if not RS.eof then RS.movefirst Do loginsuccess = "1" UsersId = RS("UsersId") UId = RS("UsersId") nick = RS("nick") role = RS("role") level = RS("levels") Pass= RS("passwords") Email = RS("email") RS.movenext Loop until RS.eof RS.movefirst End if if loginsuccess = "1" then Response.Cookies("uId")("uIds") = UsersId Response.Cookies("UId")("UId") = UId Response.Cookies("username")("Nick") = nick Response.Cookies("role")("roles") = role Response.Cookies("level")("levels") = level Response.Cookies("email")("emails") = Email Response.Cookies("Password_current")("Pass")= Pass SQL = "" SQL = SQL & "INSERT INTO users_online(nick)VALUES(" SQL = SQL & "'"&nick&"')" Mysql_Query oCn,SQL erorre = errore & "Redirect in corso" Response.Write("<meta http-equiv='refresh' content='4;URL="&strUrl&"'") End if else errore = errore & "Spiacente la tua password non coincide con il tuo username" End if else errore = errore & "Non hai inserito il codice essato" End if else End if else %> <form method="POST" action="login.asp" name="login"> <p><%=errore%></p> <input type="hidden" name="act" value="entra"> <div class="right"> <p> </p> <table width="100%" border="0" cellspacing="2" cellpadding="2"> <tr> <td colspan="2">Benvenuto nell'area riservata se non ti sei ancora registrati vai in questa pagina (<a href="registrati.asp" class="a">registrati</a>) e riempi il modulo</td> </tr> <tr> <td width="25%"> </td> <td width="75%"> </td> </tr> <tr> <td><label for="name2">Email:</label></td> <td><input type="text" name="email" value="<%=email%>" /></td> </tr> <tr> <td><label for="name3">Password:</label></td> <td><input type="text" name="password" value="<%=loginpassword%>" /></td> </tr> <tr> <td height="35"> </td> <td> </td> </tr> <tr> <td>Codice di sicurezza</td> <td><img src="/captcha.asp" alt="" id="imgCaptcha" /><br /> <a href="javascript:void(0)" onclick="RefreshImage('imgCaptcha')" style="color:#000000;">Change Image</a></td> </tr> <tr> <td>Inserire codice sicurezza</td> <td><input name="captchacode" type="text" id="captchacode" size="10" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="invia" value="Accedi" /></td> </tr> </table> <p> </p> </div> </form> <% End if %> <%=errore%> <!-- #include virtual="/footer.asp" --> -
ho sistemato la parte della pagina (login).
ecco il codice:<!-- #include virtual="/inc.asp" --> <!-- #include virtual="/header.asp" --> <% function TestCaptcha(byval valSession, byval valCaptcha) dim tmpSession valSession = Trim(valSession) valCaptcha = Trim(valCaptcha) if (valSession = vbNullString) or (valCaptcha = vbNullString) then TestCaptcha = false else tmpSession = valSession valSession = Trim(Session(valSession)) Session(tmpSession) = vbNullString if valSession = vbNullString then TestCaptcha = false else valCaptcha = Replace(valCaptcha,"i","I") if StrComp(valSession,valCaptcha,1) = 0 then TestCaptcha = true else TestCaptcha = false end if end if end if end function action = Request.Form("act") email=Request.Form("email") loginpassword=Request.Form("password") if action ="entra" then if email = "" then errore = errore & "<p style='background-color:red;font-size:20px;'>Non hai inserito l'email</p>" elseif loginpassword = "" then errore = errore & "<p style='background-color:red;font-size:20px;'>Non hai inserito la password</p>" Elseif not IsEmpty(Request.Form("invia")) then if TestCaptcha("ASPCAPTCHA", Request.Form("captchacode")) then SQL = "SELECT * FROM users WHERE email = '" & email & "' and passwords = '" & loginpassword & "' and locks='2';" Set RS = MySql_Rows(oCn, SQL) if not RS.eof then RS.movefirst Do loginsuccess = "1" UsersId = RS("UsersId") UId = RS("UsersId") nick = RS("nick") role = RS("role") level = RS("levels") Pass= RS("passwords") Email = RS("email") RS.movenext Loop until RS.eof RS.movefirst else erorre = errore & "<p style='background-color:green;font-size:20px;'>Nessuna Password o email nel db</p>" End if if loginsuccess = "1" then Response.Cookies("uId")("uIds") = UsersId Response.Cookies("UId")("UId") = UId Response.Cookies("username")("Nick") = nick Response.Cookies("role")("roles") = role Response.Cookies("level")("levels") = level Response.Cookies("email")("emails") = Email Response.Cookies("Password_current")("Pass")= Pass SQL = "" SQL = SQL & "INSERT INTO users_online(nick)VALUES(" SQL = SQL & "'"&nick&"')" Mysql_Query oCn,SQL erorre = errore & "Redirect in corso" ' Response.Write("<meta http-equiv='refresh' content='4;URL="&strUrl&"'") End if Response.Redirect("registrato.asp") else errore = errore & "<p style='background-color:red;font-size:20px;text-align:center;'>Errore codice non in uso</p>" end if end if End if %> <div style="margin-left:10px;"> <form method="POST" action="<%=strUrl%>" > <p><%=strUrl%></p> <p><input type="hidden" name="act" value="entra"></p> <table width="100%" border="0" cellspacing="4" cellpadding="4"> <tr> <td colspan="2" align="center" valign="middle" >Benvenuto nell'area riservata se non ti sei ancora registrati vai in questa pagina (<a href="registrati.asp" class="a">registrati</a>) e riempi il modulo</td> </tr> <tr> <td colspan="2">Errore: <% Response.Write(errore) %> </td> </tr> <tr> <td width="39%">Insrire l'email per entrare</td> <td width="61%"><input type="text" name="email" value="<%=email%>" /></td> </tr> <tr> <td>Inserire la password per entrare</td> <td><input type="text" name="password" value="<%=password%>" /></td> </tr> <tr> <td>Codice di sicurezza</td> <td><img src="/captcha.asp" alt="" id="imgCaptcha" /><br /> <a href="javascript:void(0)" onclick="RefreshImage('imgCaptcha')" style="color:#000000;">Change Image</a></td> </tr> <tr> <td>Inserire codice sicurezza</td> <td><input name="captchacode" type="text" id="captchacode" size="10" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="invia" value="Accedi!" /></td> </tr> </table> <p> </p> </form> </div> <!-- #include virtual="/footer.asp" --> -
prima della riga "if not rs.eof"...metti una riga "if rs.eof"...
Mentre la prima condizione gli dice che se non è alla fine del file (eof=end of file), e quindi vuol dire che ha trovato un record dove corrispondono username e password inseriti, nella condizione if rs.eof gli dici di restituire il messaggio che indica di non aver trovato record corrispondenti....quindi potresti mettere qualcosa tipo:
if rs.eof then response.write "Attenzione! Non esistono Username e Password inseriti!"
poi sistemalo tu che vedo che assegni il valore della variabile errore, e poi la stampi in base al caso...
Ciao
-
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi