ai didi

mysql - Request.form 返回带逗号的值

转载 作者:行者123 更新时间:2023-11-29 10:56:25 24 4
gpt4 key购买 nike

当我运行此代码时:

string MySQL = "Select * From RegisterDatabase Where uName  = '" + Request.Form["username"] +"'";

它对我不起作用,所以我试图看看问题出在哪里,结果发现 MySQL 中有一个逗号。

Select * From RegisterDatabase Where uName  = 'Test,'

如何解决这个问题?

最佳答案

您的代码容易出现SQL Injection attack

您想要像这样参数化查询 -

string query = "Select * From RegisterDatabase Where uName = @username";

// Remove "," from username
string username = Request.Form["username"].ToString().Replace(",", "");

MySqlCommand command = new MySqlCommand(query);
command.Parameters.AddWithValue("@username", username);

或者有些使用?username而不是@username

关于mysql - Request.form 返回带逗号的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42955681/

24 4 0
文章推荐: mysql - 使用 AngularJS 和 Spring Security 进行身份验证
文章推荐: iphone - NSRangeException 错误
文章推荐: ios - 如何在 ios 中使用 google Analytics,而无需在所有库中扩展库 GAY Tracked ViewController
文章推荐: MySQL 数据库无法正确处理非拉丁字符
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com