任何人都可以建议如何编写代码以将他/她的出生日期作为用户的输入在数据库中存储它。
答案 0 :(得分:0)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>..................</title>
<script language="javascript">
function doCheck()
{
var s1=document.getElementByName("DateofBirth");
if(s1.value == "")
{
alert ("enter the DateofBirth");
s1.focus();
return false;
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="store.jsp">
<input type="text" NAME="DateofBirth" />
<input type="submit" name="Submit" value="Submit"/>
</form>
</body>
</html>
将其另存为abc.jsp 然后创建新文件
<%
try {
String s1 = request.getParameter("DateofBirth");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connectioncon1=DriverManager.getConnection("Jdbc:mysql://localhost:3306"username", "password");
Statement st = con1.createStatement();
System.out.println("insert into userregistrations values('" + s1 "')");
st.executeUpdate("insert into userregistrations values('" + s1 + "')");
out.println("Congrats!!Now, You have sucessfully registered");
}
catch (Exception e) {
out.println(e);
}
%>
将文件另存为store.jsp