输入标签的值被传递为null到数据库中
本文关键字:null 数据库 标签 输入 | 更新日期: 2023-09-27 18:21:00
以下是我的项目。我想添加评论表单,但在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"]"