连接HTML网页与mssql数据库
Connecting HTML web page with mssql database
我试图将我的html表单连接到通过godaddy.com托管的数据库。我有通过SQL Server管理工作室表设置数据库,我有我的html表单在微软Visual Studio 2012。SQL连接到我的godaddy帐户。我无法弄清楚的是如何将我的表单连接到SQL。我能用js或php或c#做些什么吗?我只需要一个基本的例子来说明如何把它们联系起来,我想我能弄清楚。
这是我的代码。
<html>
<head>
<script type="text/javascript">
function trim(tbx) { tbx.value = (tbx.value).trim(); }
function done(){
frm = document.LoginForm;
var checkString = function(testChar, alpha, num, specialChars){
if(alpha!==true)alpha=false;
if(num!==true)num=false;
if(specialChars==null)specialChars="";
for(tc = 0; tc < testChar.length;tc++){
var r = true;
if(!alpha && testChar[tc].match(/^[a-z]+$/i)) return false;
if(!num && testChar[tc].match(/^[0-9]+$/i)) return false;
if(!testChar[tc].match(/^[a-z0-9]+$/i) && !checkSpecialChars(testChar[tc])) return false;
}
return true;
function checkSpecialChars(c){
for(sc = 0; sc < specialChars.length;sc++){
if(specialChars[sc]==c){
return true;
}
}
return false;
}
}
function test_name(name){
var t = name;
if (t.length<2 || t.length>35){
alert("Names must be between 2 and 35 letters.");
return false;
}
else {
if (!checkString(name,true,false,"'- ")){
alert("Names are made up of letters and sometime apostasies, dashes and spaces.");
return false;
}
}
return true;
}
function test_un(){
var t = frm.un.value;
if (t.length<5 || t.length>14){
alert("Usernames must be between 5 and 14 letters.");
return false;
}
else
for(i=0;i<t.length;i++){
if (i==0){
if (!t[i].match(/^[a-z]+$/i)){
alert("Usernames must start with a letter.")
return false;
}
}
else if (!checkString(t[i],true,true,"_")){
alert("Usernames must be made up of letters, numbers and underscores.");
return false;
}
}
return true;
}
function test_pw(){
var t = frm.pw.value;
if (t.length<7 || t.length>14){
alert("Passwords must be between 7 and 14 letters.");
return false;
}
if (t!==frm.pc.value) {
alert("Your password and password confirmation do not match.")
return false;
}
for(i=0;i<t.length;i++){
if (!checkString(t[i],true,true,">@!#$%^&*()_+[]{}?:;|''"'',./~`-=")){
alert("Passwords must be made up of: 'n - at least one letter 'n - numbers 'n - any of the following: 'n <>@!#$%^&*()_+[]{}?:;|''"'',./~`-=");
return false;
}
}
return true;
}
if (!test_name(frm.fn.value)){
frm.fn.focus();
frm.fn.select();
}
else if (!test_name(frm.ln.value)){
frm.ln.focus();
frm.ln.select();
}
else if (!test_un()){
frm.un.focus();
frm.un.select();
}
else if (!test_pw()){
frm.pw.focus();
frm.pw.select();
}
else{
alert(
"Name: " + frm.fn.value + " " + frm.ln.value + "'n" +
"Username: " + frm.un.value + "'n" +
"Password: " + frm.pw.value);
frm.fn.value = "";
frm.ln.value = "";
frm.un.value = "";
frm.pw.value = "";
frm.pc.value = "";
frm.fn.focus();
}
}
</script>
<title>TEST</title>
</head>
<body>
<form name="LoginForm"><table style="width:300px">
<table>
<tr><td>First Name: </td> <td><input type="text" name="fn" onblur="trim(document.LoginForm.fn);" /></td></tr>
<tr><td>Last Name: </td> <td><input type="text" name="ln" onblur="trim(document.LoginForm.ln);" /></td></tr>
<tr><td>Username: </td> <td><input type="text" name="un" onblur="trim(document.LoginForm.un);" /></td></tr>
<tr><td>Password: </td> <td><input type="password" name="pw" /></td></tr>
<tr><td>Confirm: </td> <td><input type="password" name="pc" /></td></tr>
<tr><td><input type="Button" value="Submit!" onClick="done()" /></td></tr>
</table>
</form>
<form name="UserList">
<table border="1px">
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>last Name</th>
<th>Username</th>
<th>Password</th>
</tr>
</thead>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<br />
</form>
<script type="text/javascript">
</script>
</body>
您需要使用一些服务器端技术将其连接到数据库(Javascript也可以用作服务器端技术,例如:Node.js)既然你熟悉c#,我想你可以用asp
点击这个链接,会对你有帮助的
http://msdn.microsoft.com/en-us/library/ms178371 (v = vs.100) . aspx
方法是将web服务托管在GoDaddy
上(您在问题中提到了c#)。它很容易在c#中实现…)。
webservice将知道如何:
- 从客户端获取请求(比如你的HTML站点)
- 查询数据库
你的HTML站点可以使用javascript与web服务通信。
你可以在这里看看如何用c#实现web服务
相关文章:
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 如何通过php页面将数据库值检索到jquery自动完成框中
- 使用javascript从数据库中添加表
- 通过CSV文件上载更新数据库表
- 平均值:无法将数据更新到数据库
- 如何使用 Angular JS 将数据保存在数据库中
- Rails-JQueryUIAutcomplete和AJAX不工作,可以't连接到数据库
- 在谷歌地图上绘制位置数据库
- PHP:显示sqlite数据库中的html格式数据,使用tinymce保存
- 将地理编码结果转换为php变量以发布到mysql数据库
- 从数据库中检索字段,而不模拟它们
- javascript:将数据库中的数据插入到html5文本字段中
- 从数据库中获取数据并插入JavaScript变量
- JavaScript,PHP-用JavaScript将多个数据库记录发送到变量或表
- 从MySQL数据库中获取输入数据需要两次页面刷新
- 在javascript中接收来自mssql.query的变量
- 使用PHP将线索从MSSQL数据库发布到另一个网站
- 如何检索数据从mssql数据库到json代码与asp.net
- 如何使页面上的Javascript可以使用MSSQL查询数据,而无需再次查询数据库
- 连接HTML网页与mssql数据库