$.ajax({
type: "POST",
url: "__URL__/ajax",
data: "act=CkUser&username="+$('#username').val()+"&userid="+$('#userid').val(),
success: function(msg){
if(msg>0){
alert("用户名已存在!")
$('#username').val('')
}
}
})
}
<input name="username" type="text" class="input" id="username" size="20" value="{$rs.username}" onblur="CkUser()" />
<php>
$act = trim($_POST["act"])
switch($act)
{
case "CkUser":
$username = trim($_POST["username"])
$userid = intval($_POST["userid"])
$db = M("userinfo")
$num = $db->where("username='$username' and userid!=$userid and isdel=0")->count()
echo $num
break
}
要连接数据库一定要使用动态脚本语言,比如php、asp、jsp等等。DW只是一个工具,它支持这些语言,但要真正掌握好,灵活运用,必须得对这些语言有所了解。比如用php连接SQL Server的脚本大概如下:
<?php
$serverName = "SQLServer服务器IP地址"
$uid = "SQLServer有效用户"
$pwd = "密码"
$connectionInfo = array("UID"=>$uid,
"PWD"=>$pwd,
"Database"=>"默认数据库")
/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect($serverName, $connectionInfo)
if( $conn === false )
{
echo "Unable to connect.</br>"
die( print_r(sqlsrv_errors(), true))
}
?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)