php 5.6某些功能的问题

时间:2016-06-04 14:11:53

标签: php php-5.6

xampp上的php 5.6存在一些问题。

我发现有些功能不起作用。即mysqli_connect_error和mysqli_num_rows。

我正在使用Atom作为我的文本编辑器,并且这些特定功能的颜色不对。

有人可以向我解释原因吗?有办法解决这个问题吗?

干杯

<?php

session_start();

$host = 'localhost';
$user = 'tim_williams';
$pass = 'baroness';
$db  = 'php_db05';

$link = mysqli_connect($host, $user, $pass, $db);

if(!$link) {
  die("Database connection failed: " . mysqli_connect_error());
}

//if click on log in and fields are populated
if(isset($_POST['login']) && !empty($_POST['username']) && !empty($_POST['password'])) {

    $username = ($_POST['username']);
    $password = ($_POST['password']);






// Check for matching row
    $sql = "SELECT  *
            FROM    registeredusers
            WHERE   UserName = '$username'
            AND     Password = '$password'";



  //run query
  $select = mysqli_query($link,$sql);
  //store result as array
  $result = mysqli_fetch_array($select);
  //count number of rows
  $count = mysqli_num_rows($select);



  //if count has a value of one returned row
  if($count === 1) {
  //set query
      $qry = "UPDATE  registeredusers
              SET     LastLogin = NOW(),
                      NumLogins = (NumLogins+1)
              WHERE   UserName = '$username'";

  //run query
      $update = mysqli_query($link, $qry);

// Set SESSION vars to store login
    $_SESSION['user']['login']      = true;
    $_SESSION['user']['name']       = $user['FirstName'].' '.$user['Surname'];
    $_SESSION['user']['username']   = $user['UserName'];
    $_SESSION['user']['id']         = $user['UserID'];

// Redirect

    header("Location: mysql-project-users-manage.php");
    exit;

    } else {
    echo "Please enter your details again, either your password or user name is incorrect.";
  }
}

mysqli_close($link);


?>




<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="./css/layout.css" media="screen" type="text/css" charset="utf-8">
    <link rel="stylesheet" href="./css/menu.css" media="screen" type="text/css" charset="utf-8">
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <div class="holder">

      <div class="header"></div>
      <div class="navbar">
        <nav>
          <ul>
            <li><a href="mysql-project-users-login.php">Login</a></li>
            <li><a href="mysql-project-users-add.php">Register</a></li>
          </ul>
        </nav>
      </div>
      <div class="content">
        <div class="pageheading">
          <h1>User Log In</h1>
        </div>
        <div class="contentleft">
          <h2>Welcome back to my website</h2><br />
            <h6>Please enter your details to log in, or if you are a new user please register an account with us.</h6>
        </div>
        <div class="contentright">
          <form class="registerform" action="" method="post">
            <input class="styletxtfield" type="text" name="username" placeholder="Enter Username" value=""><br /><br />
            <input class="styletxtfield" type="password" name="password" placeholder="Enter Password"value=""><br /><br />
            <input type="submit" name="login" value="Log in">
            <input type="submit" name="register" value="Register"><?php if(isset($_POST['register'])) { header("Location: mysql-project-users-add.php");}?>
          </form>

        </div>

      </div>
      <div class="footer"></div>

    </div>

</body>
</html>

0 个答案:

没有答案