问题
Does anyone know why this statement
Response.write(rs.Fields.Item("password")&" ; "&rs.Fields.Item("password"))
Do this :
myPass ;
It's very strange and I'm looking for a solution since this morning. It's making me crazy because the result of this is that this codntion :
if rs("password") = rs("password") then
is False !
EDIT :
After other test, i have made an other discover :
Response.write(rs.Fields.Item("name")&" ; "&rs.Fields.Item("name"))
do :
amdin ; admin
And if i change "password" by his ordinal index it doing the same displays :
myPass ;
.
EDIT : the related code :
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=crm_sandbox; UID=root;PASSWORD=tahina; OPTION=3"
if Request.Form("login") <> "" or Request.Form("mdp") <> "" or Request.Form("redirect") <> "" then
Response.write(Request.Form("mdp")&" ; "&Request.Form("login")&" ; "&Request.Form("redirect")&"<br>")
if Request.Form("login") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre nom d'utilisateur.</p>"
elseif Request.Form("mdp") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre mot de passe.</p>"
elseif Request.Form("login") <> "" and Request.Form("mdp") <> "" then
sql = "SELECT id, mdp, nom, initiales, couleur, droit FROM connection WHERE nom='"&Request.Form("login")&"';"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql, conn
if rs.eof then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Nom d'utilisateur inconnu.</p>"
elseif rs("mdp") <> Request.Form("mdp") then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Mot de passe incorect.</p>"
elseif Request.Form("mdp") = rs("mdp") then
Session("util_id") = rs("id")
Session("util_nom") = rs("nom")
Session("util_couleur") = rs("couleur")
Session("util_initiales") = rs("initiales")
Session("util_droit") = rs("droit")
Session.Timeout = 660 'On créer une session de 11 heures
rapport = "<p style='color: green; font-weight: bold;'>Vous êtes à présent connecté !</p>"
if Request.Form("redirect") <> "" then
rapport = rapport&"<p>Vous allez être rédirigé vers votre page dans 3 secondes</p>"
end if
end if
end if
end if
回答1:
I've actually had this issue before, when the page made it's first run, the first value of the recordset(value) returns a value, but upon second reading of recordset(value) it returned null. Or excactly what is happening with your current set up.
This is not actually a very well known issue, but there are still several support forums and questions answer along the same lines.
Example Page 1
Example Page 2
There are acouple theories that could cause this, such as, not having the correct data type in the table column data type specifier. A glitch in the recordset object that only returns the value once, and thus, must be stored in an object instead.
Because it is the second calling of the same variable that is returning Null
E.g.
' [Good Read-out] - object empties itself
if rs( "password")_
= rs("password") then
' [Bad Read-out] - object no longer contains values.
This is NOT a blanket statement occurrence, this is an anomaly, a glitch, something that doesn't have a solid reason behind it's minimal prevalence beyond the ghost in the machine.
To fix this:
Only read out the variables from the current record ONE time. This will not allow the object to empty and thus you can compare your checks later on in your code without any fuss.
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=crm_sandbox; UID=root;PASSWORD=tahina; OPTION=3"
if Request.Form("login") <> "" or Request.Form("mdp") <> "" or Request.Form("redirect") <> "" then
Response.write(Request.Form("mdp")&" ; "&Request.Form("login")&" ; "&Request.Form("redirect")&"<br>")
if Request.Form("login") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre nom d'utilisateur.</p>"
elseif Request.Form("mdp") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre mot de passe.</p>"
elseif Request.Form("login") <> "" and Request.Form("mdp") <> "" then
sql = "SELECT id, mdp, nom, initiales, couleur, droit FROM connection WHERE nom='"&Request.Form("login")&"';"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql, conn
'------------------------------------------------
'Place record set values in variables first.
Dim rMDP, rID, rNom, rCouleur, rInit, rDroit
rMDP = rs("mdp")
rID = rs("id")
rNom = rs("nom")
rCouleur = rs("couleur")
rInit = rs("initiales")
rDroit = rs("droit")
'------------------------------------------------
if rs.eof then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Nom d'utilisateur inconnu.</p>"
elseif rMDP <> Request.Form("mdp") then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Mot de passe incorect.</p>"
elseif Request.Form("mdp") = rMDP then
Session("util_id") = rID
Session("util_nom") = rNom
Session("util_couleur") = rCouleur
Session("util_initiales") = rInit
Session("util_droit") = rDroit
Session.Timeout = 660 'On créer une session de 11 heures
rapport = "<p style='color: green; font-weight: bold;'>Vous êtes à présent connecté !</p>"
if Request.Form("redirect") <> "" then
rapport = rapport&"<p>Vous allez être rédirigé vers votre page dans 3 secondes</p>"
end if
end if
end if
end if
回答2:
Always retrieve the recordset values and place them in the variables, then manipulate them. I learned some strange issues with rs values in first days I started using classic ASP some 15 years ago.
来源:https://stackoverflow.com/questions/23340622/asp-recordset-fileds-are-empty-at-second-utilisation