Ä stored as ä is encoded in the database

I write out the variable on the asp page:

name="ända" response.write name 

He shows ända on the page, alright!

When pasted into a database, the value written to the database is ända

Page encoded with <%Response.charset="iso-8859-1"%>

How can I write this ända value to the database?

 <%Response.charset="iso-8859-1"%> folderName=request.querystring("foretagsnamn") folderName = replace(folderName, "å" , "a") folderName = replace(folderName, "ä" , "a") folderName = replace(folderName, "ö" , "o") folderName = replace(folderName, "Å" , "a") folderName = replace(folderName, "Ä" , "a") folderName = replace(folderName, "Ö" , "o") folderName = LCase(folderName) response.write folderName 

And then just paste sql into the database.

 sql="INSERT INTO users(folderName) VALUES('"&folderName&"');" conn.execute(sql) 

Its database is mySql, a classic asp.

The request is executed from the credit card payment service, and it is strange that when I complete the transaction and I exit the query line, this is wrong, but if I just refresh the page to run the code again and repeat the request, is that right !?

+4
source share
3 answers

URL parameters are URL encoded, and you need to decode the URL parameter values ​​to get the original values.

For example, see this implementation of URLDecode

In the case of & # 228; nda, this is HTML encoding, and you will find the HTML decoding function at the same address.

Not sure why you get a string encoded in HTML format as the result of querystring ().

+2
source

Ahh - use Bind Parameters instead of just concatenating your SQL statement together. This solves a number of problems (performance, SQL injection, etc.)

EDIT: I haven't played with MySQL after a while, but the idea is this:

 command = new Command("INSERT INTO USERS(folderName) VALUES (@folderName)"); command.Parameters.Add(new MySqlParameter("@folderName", DbType.NVarChar, 255, folderName)); command.ExecuteNonQuery(); 

In addition, folder_name must be a Unicode column (NCHAR or NVARCHAR).

+1
source

It seems to be passing through querystring as the wrong value. Where does the value come from? There seems to be a problem here.

0
source

Source: https://habr.com/ru/post/1339864/


All Articles