0

我正在登录,我希望 ajax 将每个键击发布到查询中。当登录名与数据库(mySQL)中的登录名匹配时,我希望将密码返回到父页面。这就是现在的全部。我过去曾使用 ajax 将 php 发布到数据库,但从未返回变量。我也不知道我是否传递了表单信息,谢谢!

index.php 脚本:

$(function(){

    $("#inputEmail").keyup(function() {
    var UsernameInput = $(this).val();
        $.ajax({
            type: "POST",
            url: "PullUserDb.php",
            data: { 'UsernameInput':UsernameInput },
            dataType: "text",
            success: function(data)
            {
            $('.body').html(data);
            }
        });
    });

});

index.php HTML:

 <div class = "HeaderLogin">
        <form class="LoginForm">
            <div class="control-group">
                    <div class="controls">
                    <input style = "height: 30px" type="text" id="inputEmail" placeholder="Email">
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                <input style = "height: 30px" type="password" id="inputPassword" placeholder="Password">
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <button style = "width: 200px" type = "button" class="SubmitLogin">Sign in</button>
                </div>
            </div>
        </form>
    </div>

拉用户数据库.php:

<?php
//Connect to the server
$db_server = mysql_connect('localhost','root','');
if(!$db_server) die("Unable to connect to MySQL: " . mysql_error());
?>

<?php
//Connect to the database
mysql_select_db('databases')
    or die("Unable to select database: " . mysql_error());
?>

<?php
$Input_Username = $_POST['UsernameInput'];
//Pull columns and store them into variables
$query_users = "Select *

                FROM users

                WHERE Username = '".$Input_Username."'";

$result_users = mysql_query($query_users);
if (!$result_users) die ("Database access failed: " . mysql_error());

while($row_user_fetch = mysql_fetch_array($result_users))
   {
        $Username = $row_users_fetch['Username'];
        $Password = $row_users_fetch['Password'];
        $Email = $row_users_fetch['Email'];
        echo $Email;
   }
?>
4

1 回答 1

0

我想到了!此代码已被编辑以显示其他需要它的人!当您输入一个好的用户名时,以下代码会将相应用户的电子邮件回显到 Body CLASS DIV。

于 2013-07-25T04:03:56.813 回答