ERROR WITH MY PHPCODE filtervalues loop (1 Viewer)

adewale4favour

Registered User.
Local time
Today, 06:05
Joined
Aug 9, 2019
Messages
55
Hi,
Really would appreciate your support here. I have a project, part of the module in this is to build html form tied to sql database where values can be filter. I am trying to use the php script to get this done. But I have a challenge as some sort of error keep coming up. Code as below:

$filtervalues = $_GET['search'];
$query = "SELECT * FROM users WHERE CONCAT(CabNo, TruckNo, driverSAP) LIKE '%$filtervalues%'";
$query_run = mysqli_query($conn, $query);
if(mysqli_num_rows($query_run)>0)

From the code, the error throwing up is from the bold script; error is as below:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\fleetrecords\process.php on line 8
No Record Found

I am pretty new with coding in php, kindly see if you could help out.

Thanks. I will provide any other request
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:05
Joined
Jul 9, 2003
Messages
16,244
I note that your post has yet to receive a reply, hence I am taking this opportunity to bump it up the list, and let's see if it gets another look!
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:05
Joined
Sep 21, 2011
Messages
14,041

plog

Banishment Pending
Local time
Today, 08:05
Joined
May 11, 2011
Messages
11,611
Never trust yourself to build strings correctly. Just typing in here is challenge enough without making a misspelling. Trying to build one inside a variable making use of other variables is almost impossible.

$query is not a valid query. H'ers the documentation for mysqli_query():



It returns a false (e.g. boolean) value when you pass it an invalid query.

So, you need to find out exactly what is in $query and fix it
 

Steve R.

Retired
Local time
Today, 09:05
Joined
Jul 5, 2006
Messages
4,617
I don't have an actual solution based on the error message you were getting. What I do have is similar code that you could potentially adapt to your situation that may get around the error message. Additionally, the code below uses some PHP functions to "clean-up" the search string for characters that may unexpectedly cause problems. The basic distinction of my code from your code is that I have used a while statement after $rows = mysqli_num_rows($result);

There is also some addtional logic in the code below, that enables an edit feature that I have. That code is probably unnecessary for you. I hope that the sample code will be useful for you.

Code:
login();
    $search = ($_REQUEST['AuthorSearch']);
    if (get_magic_quotes_gpc())
        {
            $search = stripslashes($search);
        }
    $search = mysqli_real_escape_string($conn,$search);
    $words = explode(" ", $search);
    $phrase = implode("%' AND AuthorLast LIKE '%", $words);

    $query = "SELECT AuthorIDNUM,AuthorFirst,AuthorLast from tblAuthorList where AuthorFlag AND (AuthorLast like '%$phrase%' OR AuthorFirst like '%$phrase%')
                ORDER BY AuthorLast, AuthorFirst";
    $result =$conn->query($query);
    if (!$result) die($conn->error);

    echo "<h2 style='text-align: center;' >Author Search Results</h2>\n";
    if ($_SESSION['editbol']==intval(1))
        {echo "<h3 style='text-align: center;' >Edit Feature in Effect</h3><br>\n";}

    echo "<div id='show_author_list_table'>";
    echo "<table>";
    $rows = mysqli_num_rows($result);
    while($row=mysqli_fetch_array($result, MYSQLI_ASSOC))
        {
            $authoridnum=$row['AuthorIDNUM'];
            $authorfirst=$row['AuthorFirst'];
            $authorlast=$row['AuthorLast'];
            echo "<tr><td> <a href='index.php?content=show_author_stories&authoridnumvar=$authoridnum &strvar=$search &webtxtvar=$webtext &webvar=$webpage'>$authorfirst $authorlast</a></td></tr>";
        }
    echo "</table>";
    echo "</div>";
    $conn->close();
 

Users who are viewing this thread

Top Bottom