PDA

View Full Version : unable to edit/update


icecarim
11-25-2009, 06:11 PM
i guy's!!! can i ask for help on my code im lost.,,.
plz!! realy need your help guy's!!!
here's my code
<<<<<edit.asp>>>>>>
<%
DIM mySQL, objRS
mySQL = "SELECT Email FROM tblcontact"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, adoConn
%>

<p>To change your fields, enter your Email below:</p>

<form name="Updatetest" method="Post" action="edit2.asp">
<table>
<tr><td>Email: </td>
<td><input type="text" name="Email" size="50"></td></tr>
</table>

<input type="submit" name="Submit" value="Submit">

<<<<<<edit2.asp>>>>>
<%
DIM strUsername
strUsername = Request.Form("Email")
IF strUsername <> "" THEN
%>

<!--#INCLUDE VIRTUAL="connection.asp" -->

<HTML>
<HEAD>
<Title>edit2.asp</Title>
<META http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<META name="Generator" content="Asp Studio 1.0">
</HEAD>

<BODY>

<%
DIM mySQL, objRS

mySql = "SELECT Email FROM tblcontact WHERE Email = ' " & strUsername & " ' "
Set objRS = Server.CreateObject("ADODB.Recordset")
'objRS.Source = "tblcontact"
objRS.ActiveConnection= adoConn
objRS.CursorType= 1
objRS.LockType= 2
objRS.Open mySql
IF objRS.EOF THEN
Response.Write "<div align='center'>Sorry, that email does not exist. Please click back on your browser and enter a different email.</div>"

ELSE
%>

<form name="Updatetest" method="post" action="confirme.asp">
<table>
<tr><td>Customer:</td><td>
<input type="text" name="Username" size="50" value='<%=objRS("Email")%>'>
</td></tr>
<tr><td>Password:</td><td>
<input type="text" name="fname" size="50" value='<%=objRS("Fname")%>'>
</td></tr>
<tr><td>Password:</td><td>
<input type="text" name="lname" size="50" value='<%=objRS("Lname")%>'>
</td></tr>
</table>
<input type="submit" name="Submit" value="Submit">
</form>

<%
END IF

objRS.Close
Set objRS = Nothing
adoConn.Close
Set adoConn = Nothing
%>

</BODY>

</HTML>
<%
ELSE
Response.Write "Please click back on your browser and enter your username."
END IF
%>
<<<<confirme.asp>>>>
<!--#INCLUDE VIRTUAL="connection.asp" -->

<%
DIM mySQL, objRS
mySQL = "SELECT * FROM tblcontact WHERE Email = '" & strUsername & "'"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL 'adoConn, adOpenKeyset, adLockPessimistic, adCmdText

objRS.ActiveConnection = adoConn
objRS.CursorType= 1
objRS.LockType= 2

objRS.MoveFirst
objRS("Fname") = Request.Form("fname")
objRS("Lname") = Request.Form("lname")
objRS("DateContacted") = Date()
objRS.Update

objRS.Close
Set objRS = Nothing

Response.Write "<div align='center'>" & strUsername & ",<br>"
Response.Write " Your password has been succesffully updated in our database.<br><br>"

objRS.Close
Set objRS = Nothing
adoConn.Close
Set adoConn = Nothing
%>

<<<connection.asp>>>>
<!-- #INCLUDE file="database.inc" -->

<%

dim adoConn
set adoConn = Server.CreateObject("ADODB.Connection")

adoConn.ConnectionString = "Driver=" & dbDriver & "; Database=" & dbDatabase & "; Uid=" & dbUser & ";Pwd=" & dbPassword & ";"
adoConn.Open

%>
<<<<<database.inc>>>>
<%

dim dbDriver

dim dbDatabase

dim dbUser

dim dbPass

dbDriver = "{MySQL ODBC 5.1 Driver}"

dbDatabase = "test"

dbUser = "root"

dbPassword = "1234"

%>


hope you can help me.,,. i always get d result "Sorry, that email does not exist. Please click back on your browser and enter a different email." even i enter the right data.,., and those datas are saved with in my database.,,.thanks in advance!!:)

angst
11-25-2009, 06:24 PM
first of all welcome to the forum, however when posting please only post the relevant portion('s) of code. we really don't need to see all your connection strings and so on.

As for your problem, I'm not really seeing any issues here if the code is returning a valid error predefined error. are you sure that the email your looking up is indeed in the database?

Old Pedant
11-25-2009, 08:18 PM
Code is *WAY* over complex, but your problem is a simple one.

Look here:
mySql = "SELECT Email FROM tblcontact WHERE Email = ' " & strUsername & " ' "

If you would learn to DEBUG DEBUG DEBUG and simply do
Response.Write "DEBUG SQL: " & mySQL & "<HR>"
You would see something like
SELECT Email FROM tblcontact WHERE Email = ' john@abc.com '
NOW do you see the problem???

HINT: When comparing strings--even in SQL code--*SPACES* DO MATTER!

As it is, you are asking for an email address WITH A SPACE ON EACH END.

SO:

mySql = "SELECT Email FROM tblcontact WHERE Email = '" & strUsername & "' "