Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
part of index.php:
<pre lang="HTML">
<pre>					<div class="form">
                        <form action="results.php" method="post">
                        <p>Vyberte typ hladania:    
                        <select name="searchtype">
                                <option value="author">Autor</option>
                                <option value="title">Nazov</option>
                                <option value="isbn">ISBN</option>
                            </select></p>
                            <p>Zadajte hladany vyraz
                            <input name="searchterm" type="text" size="40"></p>
                            <p>
                                <input type="submit" name="submit" value="Hladat">
                            </p>
                        </form>
                    </div>
            </div>
				
         </div>
			
      </div>



and the php file results.php
PHP
<pre><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Medzikniznica - Vysledky hladania</title>
</head>
<body>
    <h1>Vysledky hladania:</h1>
    <?php
    $searchtype=$_POST['searchtype'];
    $searchterm=trim($_POST['searchterm']);
    if(!$searchtype || !$searchterm) {
        echo '<p>Nezadali ste niektory z udajov pre vyhladavanie.<br>
        Vratte sa prosim spat a skuste to znovu!</p>';
        exit;
    }
    switch ($searchtype) {
        case 'author';
        case 'title';
        case 'isbn';
            break;
        default: echo '<p>Zadali ste neplatny typ hladania.<br>Vratte sa prosim spat a skuste to znovu.</p>';
        exit;
    }

    @$db = new mysqli('localhost:3306','root','','books');
    if (mysqli_connect_errno()) {
        echo '<p>Chyba: Nepodarilo sa pripojit k databaze.<br>
        Kontaktujte prosim administratora.</p>';
        exit;
    }

    $query = "SELECT isbn, author, title FROM books WHERE $searchtype LIKE ?";
    $stmt = $db->prepare($query);
    $searchterm= '%'.$searchterm.'%';
    $stmt->bind_param('s',$searchterm);
    $stmt->execute();
    $stmt->store_result();
    
    $stmt->bind_result('$isbn,$author,$title');
    echo "<p>Pocet najdenych knih: ".$stmt->num_rows."</p>";

    while($stmt->fetch()) {
        echo "<p>Nazov: ".$title."";
        echo "<br>Autor: ".$author;
        echo "<br>ISBN: ".$isbn;
    }

    $stmt->free_result();
    $db->close();
    ?>
</body>
</html>



Error on line 42:
Fatal error: Uncaught Error: mysqli_stmt::bind_result(): Argument #1 cannot be passed by reference in D:\xampp\htdocs\results.php:42 Stack trace: #0 {main} thrown in D:\xampp\htdocs\results.php on line 42


Line 42:
PHP
$stmt->bind_result('$isbn,$author,$title');


What I have tried:

Lookup ISBN, Author, Title in PHPMyAdmin
PHP 8, apache (xampp)
MariaDB 10.4.x
Windows 11
Please help.
Posted
Updated 14-Nov-21 21:46pm

1 solution

PHP
$stmt->bind_result('$isbn,$author,$title');

You are trying to bind the results to a string. Remove the quotes around the field names.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900