简体   繁体   中英

Using PHP script to log in but wont work?

below is the index.html which shows the user the password and email entry forms

<!DOCTYPE html>
<html lang="en">
<head>


<title>Ryan Kelly</title>

<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="main.css" rel="stylesheet">

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/bootstrap.min.js"></script>


<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35774778-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async =               true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') +       '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

</head>
<body>
<?php include 'comments.php'; ?>

<div class="container">

<div class="centre">

<div class="well">
    <h1 class="titlecomment">Comment System</h1>

    <h4 class="instructions">Please login below with your username and      password</h4>

    <form class="form-horizontal">
  <div class="control-group">
  <label class="control-label" for="inputEmail">Email</label>
  <div class="controls">
  <input type="text" id="inputEmail" placeholder="Username" method="post">
  </div>
  </div>
  <div class="control-group">
  <label class="control-label" for="inputPassword" >Password</label>
  <div class="controls">
  <input type="password" id="inputPassword" placeholder="Password" method="post">
  </div>
  </div>
  <div class="control-group">
  <div class="controls">

   </div>
  </div>
  </form>

  <div class="greenbutton">
  <button type="submit" class="btn btn-success" method="login()">Login</button>
  </div>

  </div>
  <div class="footer">Created by Ryan Kelly</div>

  </div>

 </div>

and below is the PHP script which checks the email and password and then redirects the user to google, i only redirecting because i wanted to see if it logged in successfully

            <?php        

            function login() {


    $connection = mysql_connect($host, $databaseUsername, $databasePassword);

    $username = $_POST['inputEmail'];
    $password = $_POST['inputPassword'];

    mysql_select_db($connection);

    $queryUsername = "SELECT * FROM login WHERE Username='$username'";
    $queryPassword = "SELECT * FROM login WHERE Password='$password'";

    $searchQuery = mysql_query($queryUsername);
    $searchQueryDatabase = mysql_query($queryPassword);

      if($searchQuery && $searchQueryDatabase = $username && $password) {

        header('Location: http://www.google.co.uk');
      }

}
?>

hre is the problem

if($searchQuery && $searchQueryDatabase = $username && $password) {

you are not fetching the result, and also using assignment ( = ) when you likely mean comparison ( == ).

for and example

try $row = mysql_fetch_array($searchQueryDatabase);

now try something like

if($searchQuery && $row['Username'] == $username && $row['Password']==$password) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM