gpt4 book ai didi

c# - 输入标签的值将 null 传输到数据库中

转载 作者:行者123 更新时间:2023-11-29 23:49:39 25 4
gpt4 key购买 nike

这是我的项目的一些内容。我想添加评论表单,但以 html 形式添加,因为我已经出于另一个原因使用了服务器端。这是html代码:

<form id="modal_feedback" method="POST" action="#" accept-charset="UTF-8">
<p><label>Your Name<strong>*</strong><br>
<input runat="server" id="rvwname" type="text" autofocus required size="48" name="name" value=""></label></p>
<p><label>Email Address<strong></strong><br>
<input runat="server" id="rvwemail" type="email" title="Please enter a valid email address" size="48" name="email" value=""></label></p>
<p><label>Contact Number:*<br>
<input runat="server" id="rvwno" type="text" required size="48" name="contact" value=""></label></p>
<p><label>Message:<strong>*</strong><br>
<textarea runat="server" id="rvwmsg" required name="message" cols="48" rows="8"></textarea></label></p>
<p> <input runat="server" type="button" id="rvwsubmit" name="feedbackForm" value="Send" onserverclick="rvwsubmits" /> </p>
</form>

</div> <!-- #modal_window -->
</div> <!-- #modal_wrapper -->

c#的后端代码是:

protected void rvwsubmits(object sender, EventArgs e)
{
string a = rvwname.Value;
string b = rvwno.Value;
string c = rvwemail.Value;
string d = rvwmsg.Value;
string cnn = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
MySqlConnection con = new MySqlConnection(cnn);
MySqlCommand cmd = new MySqlCommand("insert into ab_db.rvw(rvw_name,rvw_no,rvw_email,rvw_msg) values('" + a + "','" + b + "','" + c + "','" + d + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();

}

最佳答案

你有

value="" 

对于所有字段

试试这个

value="@Request.Form["name"]"
value="@Request.Form["email"]"

关于c# - 输入标签的值将 null 传输到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25708448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com