help with sql

  • Thread starter Thread starter Paul M
  • Start date Start date
P

Paul M

Hi
Something is wrong with this sql but I can't put my finger on it. the
problem is after the
" pass_word='" & sPassword & "'," &

Thanks Paul M

sSQL = "UPDATE Results SET email='" & sEmail & "', user_name='" & sUsername
& "'," & _
" pass_word='" & sPassword & "'," &
" forename='" & sforename & "', WHERE ID=" & iMemberID
 
Ok
I have managed to get it to update but now it's adding the entry to the next
instead of relacing it but only on the forename field for eg, if forename
paul is displayed then I change it to paulc when I bring up the recordset
again it displays
paul, paulc
here is the sql

sSQL = "UPDATE Results SET email='" & sEmail & "', user_name='" & sUsername
& "'," & _
" pass_word='" & sPassword & "'," & _
"forename='" & sforename & "' WHERE ID=" & iMemberID


Thanks Paul M
 
To see your Update string as submitted to the DB,
For testing Only add below that line of code
Response.Write sSQL & "<br>"
Suggest you also add the below to also see what's in the variable sforename
Response.Write sforename & "<br>"
--




| Ok
| I have managed to get it to update but now it's adding the entry to the next
| instead of relacing it but only on the forename field for eg, if forename
| paul is displayed then I change it to paulc when I bring up the recordset
| again it displays
| paul, paulc
| here is the sql
|
| sSQL = "UPDATE Results SET email='" & sEmail & "', user_name='" & sUsername
| & "'," & _
| " pass_word='" & sPassword & "'," & _
| "forename='" & sforename & "' WHERE ID=" & iMemberID
|
|
| Thanks Paul M
|
|
| | > Hi
| > Something is wrong with this sql but I can't put my finger on it. the
| > problem is after the
| > " pass_word='" & sPassword & "'," &
| >
| > Thanks Paul M
| >
| > sSQL = "UPDATE Results SET email='" & sEmail & "', user_name='" &
| > sUsername & "'," & _
| > " pass_word='" & sPassword & "'," &
| > " forename='" & sforename & "', WHERE ID=" & iMemberID
| >
| >
|
|
 
I have managed to get it to update but now it's adding the entry to the
next instead of relacing it but only on the forename field for eg, if
forename paul is displayed then I change it to paulc when I bring up the
recordset again it displays
paul, paulc

I have no idea what that means.
"adding the entry to the next?" What exactly is "the entry?" What exactly is
"the next?"
"But only on the forename field?" What exactly is "the forename field?" A
form field named "forename?" Or the column in the database named "forename?"

It really helps to define your terms for those of us who can't see directly
what you're doing, and must rely on you for information.

In any case, I CAN tell you this much:

ASSUMING that you have an HTML form with a form field named "forename" (or
possibly some other form field name) (and probably some other form fields?),
and that this form is for the purpose of updating or changing a record (is
that what you mean by "entry?" If so, what is "the next," and how exactly
are you "adding the entry to the next?"), and assuming that when you change
a single form field value in the ("forename" or whatever form field name it
is) form field from "paul" to "paulc," you run a SQL UPDATE query to change
the corresponding database column value in the same record, and assuming
that the corresponding column is the "user_name" column, I have a few more
questions, and some information for you:

"it displays paul, paulc"

ASSUMING that "it" is the ASP page that displays the results of the update,
which database column does the "paul" value in your page output correspond
to, and which database column does the "paulc" value in your page output
correspond to? Which of these 2 values, and the corresponding database
column does the previous HTML form's "forename" (or whatever form field name
it is) form field correspond to?

What were the previous values of these 2 database columns prior to executing
your query?

Here's the problem: Your SQL statement is concatenating 3 variables into a
SQL statement. The 3 variables it concatenates are "sEmail," "sPassword,"
and "sUserName." I have to assume that ONE (or more) of these variables are
being assigned from the Request.Form("formfield") (or whatever form field
name it is) value in the server-side code, the code that gets the form
values from the form. We have no idea which form fields these 3 variables
are being populated from, nor which of the output values you posted
corresponds to which database column. Obviously, from the context of your
message, at least ONE of them is being assigned from the "forename" (or
whatever form field name it is) field, but again, you don't specify which
one is assigned from that form field, and you don't specify which value in
the ouput page corrresponds to which database column. Any of the 3 database
columns, "email," "user_name," or "pass_word" could have a value of "paul"
or "paulc." If I were to make a few more assumptions, I could possibly rule
out the "email" column, as the value doesn't make a fully-qualified email
address. I could possibly assume, for example, that it is the "user_name"
field, as "paul" is a name for a human being, and therefore more likely not
the password.

But again, making ALL of those assumptions, I still can't figure out which
database column in the output page is "paul" or "paulc."

Hazarding a few more wild guesses, I could guess that, rather than updating
the "user_name" field, the query is updating either the "pass_word" column,
or the "email" column. This, if correct, would indicate that one or more of
the variable assignments in your form handler page are being assigned
incorrectly from the wrong form field. Which one is anyone's guess, as you
did not identify which 2 database column values are being displayed in the
output page. I could (again) make an educated guess that ONE of them is the
"user_name" column. I could NOT guess whether the value "paul" or "paulc"
corresponded to that column. As to which of the other 2 columns is being
displayed, I could not even guess.

In summary, it is not possible to know which form field is being incorrectly
assigned to which variable(s) in the form handler page. However, it is a
fairly safe guess that the "forename" (or whatever form field name it is)
form field value is being incorrectly assigned to one of the variables used
in the query.

Finally, may I point out the lengths I have gone to (and the length of my
reply!) to ensure that you understand what I mean, in order to help you. In
the future, it would be appropriate for you to take as much trouble to make
your questions understood. This would ensure that your question is answered
more quickly, and save people like me from having to work this hard to help
you! ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
I'd rather be a hammer than a nail.
 
Thanks Kevin sorry for being vague
Here is the corrisponding code I put this at the end of the first sql
statement to see the output
Response.write(ssql)
Response.end
and recieve this
UPDATE Results SET email='(e-mail address removed)', user_name='paulcc',
pass_word='artist1',forename='Paul, Pault, paulf' WHERE ID=64

it keeps adding forenames onto the last instead of overwriting it when the
sql is run


iMemberID=Request.form("ID")
sEmail= Replace(Request.form("txtEmail"),"'","''")
sPassUsername=Replace(Request.form("txtPassUserName"),"'","''")
sPassPassword=Replace(Request.form("txtPassPassword"),"'","''")
sUserName= Replace(Request.form("txtUserName"),"'","''")
sPassword=Replace(Request.form("txtPassword"),"'","''")
sforename=Replace(Request.form("txtforename"),"'","''")

sSQL = "UPDATE Results SET email='" & sEmail & "', user_name='" & sUsername
& "'," & _
" pass_word='" & sPassword & "'," & _
"forename='" & sforename & "' WHERE ID=" & iMemberID

If sPassUsername<>sUserName Then
'Check to make sure that the username hasn't already been taken before
executing SQL
sSQLCHECK= "SELECT user_name FROM Results WHERE user_name='" & sUsername &
"';"
Set oRsCheck=Server.CreateObject("ADODB.Recordset")
oRsCheck.Open sSQLCHECK, oConnection

If Not oRsCheck.eof Then
Response.write "<br><br><div align='center'>Sorry that username has
already been taken.<br> Please click <A
HREF='javascript:history.go(-1)'>here</a> and select a new username.</div>"
oRsCheck.Close
Set oRsCheck=Nothing
Else
oConnection.execute(sSQL)
Response.write "<br><br><div align='center'>Your profile has been
successfully updated.</div>"
Response.write "<div align='center'><a
href='javascript:window.close()'>close window</div>"
End If

Else
'Same username as before has been selected
oConnection.execute(sSQL)
Response.write "<br><br><div align='center'>Your profile has been
successfully updated.</div>"
Response.write "<div align='center'><a
href='javascript:window.close()'>close window</div>"
End If
 
Well, thanks at least, Paul, for your second response, which was much more
informative! Glad you got it solved.

--

Kevin Spencer
Microsoft MVP
..Net Developer
I'd rather be a hammer than a nail.
 
Thanks Kevin
This asp stuff is all a bit new to me. You think that you have the specific
piece of code isolated but you then discover the problem accured somewhere
before
Thanks again for taking time to respond
Best wishes
Paul M
 
Back
Top