开发者

ä stored as ä value is encoded in database

开发者 https://www.devze.com 2023-02-11 09:33 出处:网络
I write out a variable on the asp page: name=\"ända\" response.write name It shows ända on the page, good!

I write out a variable on the asp page:

name="ända"
response.write name

It shows ända on the page, good!

When inserting it into the database, the value written to the database is ända

The page is 开发者_开发技巧encoded with <%Response.charset="iso-8859-1"%>

How can I get this value ända to be written 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 a sql insert to the database.

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

Its a mySql database, classic asp.

The querystring comes from a creditcard payment service, and the strange thing is that when I perform a transaction and I resive the querystring, it is wrong, but if I then just update the page so it runs the code and querystring again, it is right!?


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

For example, see this implementation of URLDecode

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

Not sure why you get an HTML encoded string as result of querystring().


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

EDIT: I haven't played with MySQL in 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();

Also, folderName must be a unicode column (NCHAR or NVARCHAR).


It seems to be passed via querystring as the wrong value. Where is the value coming from? That seems to be where the problem is being created.

0

精彩评论

暂无评论...
验证码 换一张
取 消