用户名错误的PHP登录代码

时间:2017-04-15 00:14:16

标签: php html login admin

我正在编写登录代码。我从另一个资源获得了代码。一切似乎都没问题,但它一直告诉我Alumni_ID(用户名)不存在 - 即使它确实存在。

登录的PHP代码:

  <?php
  error_reporting(E_ALL); ini_set('display_errors', 1);

 $servername = getenv('IP');
 $username = getenv('C9_USER');
 $password = "";
 $database = "c9";
 $dbport = 3306;
  $conn = mysqli_connect($servername,$username,"",$database,$dbport) or die(mysqli_error());
  if($_SERVER["REQUEST_METHOD"] == "POST"){
	
	
	$query = mysql_query("SELECT Alumni_ID, Password from 'Alumni' WHERE Alumni_ID='$Alumni_ID'"); //Query the Alumni table if there are matching rows equal to $Alumni_ID
	
	$exists = mysql_num_rows($query); //Checks if Alumni_ID exists
	$table_Alumni = "";
	$table_Password = "";
	
	if($exists = 0) //IF there are no returning rows or no existing Alumni_ID
	
	    {
                		while($row = mysql_fetch_assoc($query)) //display all rows from query
                		{
                			$table_Alumni_ID = $row['Alumni_ID']; // the first Alumni_ID row is passed on to $table_Alumni, and so on until the query is finished
                			$table_Password = $row['Password']; // the first Password row is passed on to $table_Alumni, and so on until the query is finished
                		}
                		if(($Alumni_ID == $table_Alumni_ID) && ($Password == $table_Password)) // checks if there are any matching fields
                		{
                				if($Password == $table_Password)
                				{
                					$_SESSION['user'] = $Alumni_ID; //set the Alumni_ID in a session. This serves as a global variable
                					header("location: loggedalumni/index.php"); // redirects the user to the authenticated home page
                				}
                				
                		}
                		else
                		{
                			Print '<script>alert("Incorrect Password!");</script>'; //Prompts the user
                			Print '<script>window.location.assign("index.php");</script>'; // redirects to login.php
                		}
	}
	else
	{
		Print '<script>alert("Incorrect Username!");</script>'; //Prompts the user
		Print '<script>window.location.assign("index.php");</script>'; // redirects to login.php
	}
}
?>

这就是形式:

<div class="col-lg-12">
                                <div class="nav-link" style= "text-align: center;"><h3><b>Log In</b></h3></div>
                                <form id="ajax-login-form" action=" " method="post" role="form" autocomplete="off">
                                    <div class="form-group">
                                        <label for="Alumni_ID" style= "text-align: center;">Alumni ID</label>
                                        <input type="text" name="Alumni_ID" tabindex="1" class="form-control" placeholder="Your Alumni ID" value="" autocomplete="off">
                                    </div>

                                    <div class="form-group">
                                        <label for="password" style= "text-align: center;">Password</label>
                                        <input type="password" name="password" id="password" tabindex="2" class="form-control" placeholder="Password" autocomplete="off">
                                    </div>

                                    <div class="form-group">
                                        <div class="row row-centered" style="padding-left:20px">
                                            <div class="col-xs-7">
                                                <input type="checkbox" tabindex="3" name="remember" id="remember">
                                                <label for="remember" style= "align: center;"> Remember Me</label>
                                            </div>
                                            </div>
                                            <div class="row row-centered">
                                            <div class="col-xs-5" style="padding-left:75px">
                                                <input type="submit" name="login-submit" id="login-submit" tabindex="4" class="form-control btn btn-success" style="background-color: #6a0001;" value="Log In" align="middle">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <hr>
                                                <div style="padding-left:10px">
                                                    <a href="recover.php" tabindex="5" class="forgot-password" style = "color: black">Forgot Password?</a>
                                                </div>
                                                <hr>
                                                <div style="padding-left:10px">
                                                    <a href="NewAlumni.php" tabindex="5" class="forgot-password" style = "color: black">Register Account</a>
                                                </div>
                                                <hr>
                                                <div style="padding-left:10px">
                                                    <a href="adminlogin.php" tabindex="5" class="forgot-password" style = "color: black">Admin Login</a>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                    <input type="hidden" class="hide" name="token" id="token" value="a465a2791ae0bae853cf4bf485dbe1b6">
                                </form>
                            </div>

1 个答案:

答案 0 :(得分:-1)

您没有定义变量strdup是什么

$Aliumni_ID

不正确但有效的代码

 $query = mysql_query("SELECT Alumni_ID, Password from 'Alumni' WHERE Alumni_ID='$Alumni_ID'");