douhaoqiao9304 2013-06-06 20:23
浏览 45
已采纳

用户名可用性使用AJAX和PHP对MSSQL进行检查

I have a database already full of clients. We are trying to let them setup online access. They must provide their member ID to set up their online account. I have built a test form that allows input to memberid and should check to see if we find them in the database. I have pulled my hair out trying to get this to work. I have also made CRUD so I know my connection to MSSQL is working.

What is wrong with this code?

FORM

<div class="container">
<div>Member ID: <input type="text" maxlength="10" name="uname" id="uname" /><span id="status"></span></div>
<div>Pass: <input type="password" maxlength="10" name="pwd" id="pwd" /></div>

</div>
<script type="text/javascript">
document.getElementById("uname").onblur = function() {
var xmlhttp;
var uname=document.getElementById("uname");
if (uname.value != "")
    {
        if (window.XMLHttpRequest){
              xmlhttp=new XMLHttpRequest();
            } else {
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
        xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                document.getElementById("status").innerHTML=xmlhttp.responseText;
                }
        };
    xmlhttp.open("GET","uname_availability.php?uname="+encodeURIComponent(uname.value),true);
    xmlhttp.send();
    }
};
</script>

And Here is uname_availability.php

<?php
$uname=$_REQUEST['uname'];

$server = "serveraddress";
$user = "username";
$pwd = "password";
$db = "dbname";

$conn = sqlsrv_connect($server, array("UID"=>$user, "PWD"=>$pwd, "Database"=>$db));

if($conn === false){
    die(print_r(sqlsrv_errors()));
}

$sql = "SELECT * FROM tblMembership WHERE MemberID = ".$uname."";
$stmt3 = sqlsrv_query($conn, $sql);
$row_count = sqlsrv_num_rows($stmt3);
if ($row_count === false)
{
print "<span style=\"color:red;\">We Can Not Find You :(</span>";
}
else
{
print "<span style=\"color:green;\">We Found You :)  </span>";
}
?>
  • 写回答

4条回答 默认 最新

  • dongmai6666 2013-06-07 03:39
    关注

    I ended up getting it with this...thanks for all the input...I really appreciate it all!

    $sql = "SELECT MemberID FROM tblMembership WHERE MemberID = '".$memid."'";
    $stmt = sqlsrv_query($conn, $sql);
    $row = sqlsrv_fetch($stmt);
    if (empty($row))
    {
    print "<span style=\"color:red;\">We Can Not Find You >:-(</span>";
    }
    else
    {
    print "<span style=\"color:green;\">We Found You :-)  </span>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测