Num_Rows中未选择任何数据库

Got a strange error saying that I'm not connected to a database while running a mysqli_num_rows query. Here is the code:

    <?php include("php/functions.php"); ?>
<?php
if(isset($_GET['verification']) && !empty($_GET['verification'])){  
    // Verify data  
    $hash = mysqli_real_escape_string($con, $_GET['verification']); // Set hash variable  

    $search_sql = "SELECT 'hash', active FROM members WHERE hash='".$verification."' AND active='0'";   
    $search_res = mysqli_query($con, $search_sql);
    $match = mysqli_num_rows($search_res);

Any ideas why this isn't working?

<?php include('functions.php'); ?>

Also, make sure you have your closing ?> tag in the correct place.

just try to make it include("functions.php").. I think thats your problem

<?php 
    include("functions.php"); //includes databse connection
    $search_sql = "SELECT hash, active FROM members WHERE hash='".$verification."' AND active='0'";   
    $search_res = mysqli_query($con, $search_sql);
    $match      = mysqli_num_rows($search_res);
?>

include("functions"); or include("functions.php"); ??? You forgot .php

You forget to add file extension.

<?php include("functions.php"); ?>

also put `

around hash as its reserved word by MySQL.

please try the below code:

<?php 
    include("functions.php"); //includes databse connection php file
    $search_sql = "SELECT hash, active FROM members WHERE hash='".$verification."' AND active='0'";   
    $search_res = mysqli_query($con, $search_sql);
    $match      = mysqli_num_rows($search_res);
?>

include should have a .php file as parameter. please check it.

I have changed several things in your code, please review.

If you are using the mysqli class then anything after your class instatiation should look something like:

$con = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
$con->exampleClassFunction()

using the object operator ->.

To get the num_rows your object operator would be after the query variable, like so:

$search_res = $con->mysqli_query($con, $search_sql);
$match = $search_res->mysqli_num_rows($search_res);

I also added the backticks to all applicable column names in your query:

SELECT `hash`, `active` FROM members WHERE `hash`='".$verification."' AND `active`='0'

Here is an example with your code:

//include("php/functions.php");

$DB_NAME = 'DATABASE_NAME';
$DB_HOST = 'DATABASE_HOST';
$DB_USER = 'DATABASE_USER';
$DB_PASS = 'DATABASE_PASSWORD';

$con = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);

// Added a connection error check before continuing
if (mysqli_connect_errno()) {
    printf("Connect failed: %s
", mysqli_connect_error());
    exit();
}

if(isset($_GET['verification']) && !empty($_GET['verification'])){  
    $hash = $con->mysqli_real_escape_string($con, $_GET['verification']);

    // Use back ticks on query column names, 
    // use single quotes for comparative operations
    $search_sql = "SELECT `hash`, `active` FROM members WHERE `hash` = '".$verification."' AND `active` = '0'";

    $search_res = $con->mysqli_query($con, $search_sql);
    $match = $search_res->mysqli_num_rows($search_res);
}