0

/* My functions.php has a lot of these.. but without any joins and concats and it works out great */

function get_for_TehtudTestid(){
    $mysqli = new mysqli("host", "user", "password", "db");
    global $id, $Testija, $Testitav, $Allyksus, $TestiNimi, $TestiKirjeldus, $TootajaTegevuseKirjeldus, $TestiTulemus, $MillalTestTehti;
    $stmt = $mysqli->prepare("SELECT 
    id,
    CONCAT(Kasutaja.Eesnimi,' ', Kasutaja.Perenimi) AS Testija,
    CONCAT(Tootaja.Eesnimi,' ', Tootaja.Perenimi) AS Testitav,
    Tootaja.Allyksus,
    Testityybid.TestiNimi,
    TehtudTestid.TestiKirjeldus,
    TehtudTestid.TootajaTegevuseKirjeldus,
    TehtudTestid.TestiTulemus,
    TehtudTestid.MillalTestTehti
    FROM TehtudTestid
    LEFT OUTER JOIN Kasutaja
        ON TehtudTestid.Kasutaja_id = Kasutaja.id
    LEFT OUTER JOIN Testityybid
        ON TehtudTestid.Testityybid_id = Testityybid.id
    LEFT OUTER JOIN Tootaja
        ON TehtudTestid.Tootaja_id = Tootaja.id");
    $stmt->bind_result($id, $Testija, $Testitav, $Allyksus, $TestiNimi, $TestiKirjeldus, $TootajaTegevuseKirjeldus, $TestiTulemus, $MillalTestTehti);
    $stmt->fetch();  
    $stmt->execute();
    return $stmt;

A singlepage for that:

<!doctype html>
<?php
    include 'functions.php';
    $kirjed = get_for_TehtudTestid();
    if(isset($_REQUEST['sort']))
    {
        $sorteeritud = sortObject($kirjed, getMultipleParameters());
        $kirjed = $sorteeritud;
    }
?>

    > /* <html lang="en"> <head>
    >     <meta charset="UTF-8">
    >     <title>Tehtud testide nimekiri</title> </head> <body> <h1>THE nimekiri:</h1> <table border="2">
    >     <tr>
    >         <?php
    >         //Tekitada header $column array-st
    >         foreach ($TehtudTestid_leht as $column){
    > 
    >             $direction = "";
    >             //üldjuhul ülevalt alla
    >             $arrow="&#9660;";
    >             if(isSet($_REQUEST['sort']) AND $column == $_REQUEST['sort'] AND !isSet($_REQUEST['direction'])){
    >                 $direction = "&direction=DESC";
    >                 //alt ülesse
    >                 $arrow="&#9650;";
    >             }
    >             echo "<th><a href='?sort=$column$direction'>$column $arrow</a></th>";
    >         }
    >         ?>
    >     </tr>
    >     <?php
    >     while($kirjed->fetch()){
    >         echo"
    >               <tr>
    >               <td>$id</td>
    >               <td>$Testija</td>
    >               <td>$Testitav</td>
    >               <td>$Allyksus</td>
    >               <td>$TestiNimi</td>
    >               <td>$TestiKirjeldus</td>
    >               <td>$TootajaTegevuseKirjeldus</td>
    >               <td>$TestiTulemus</td>
    >               <td>$MillalTestTehti</td>
    >               <td><a href=\"muuda_mind.php?id=$id\">Muuda andmeid</a></td>
    >               </tr>           ";
    >     }
    >     ?> </table>
    > 
    > </body> </html>
    > */

/* 

But I cannot understand why Im getting this: ï»؟ Fatal error: Call to a member function bind_result() on a non-object in /www/data06/users/t/thor.planet.ee/htdocs/Screen/functions.php on line 73

Line73 is:

$stmt->bind_result($id, $Testija, $Testitav, $Allyksus, $TestiNimi, $TestiKirjeldus, $TootajaTegevuseKirjeldus, $TestiTulemus, $MillalTestTehti);

*/

If this problem im having is just a select query, if someone knows how to solve it.. please hint about possible insert and update issues also.. how to solve those.

Thank you.

Shadow
  • 33,525
  • 10
  • 51
  • 64
Taara
  • 1
  • 2
  • 1. Why do you use a prepared statement if there is no user-supplied parameter in the query? 2. Why don't you check the result of the prepare? There is probably an error and prepare() returns a false as a result, causing the error you just described. – Shadow Sep 26 '16 at 12:12
  • At first it seems that there is no user-supplied parameter, but actually all columns should be used as a sorting parameter by just clicking on them.. then the query should be sorted by asc/desc.. without the need to do an actual sql query.. or im in a wrong path by trying something like that? – Taara Sep 26 '16 at 12:37
  • 1
    The manual page is [here](http://php.net/manual/en/mysqli.prepare.php) ... It shows as @Shadow says you are not checking the return value from `prepare` but are plowing forward assuming you have an Object ref. Had you used an `if` statement to guarantee not FALSE then this would not have occurred and that is why this question closes to that dupe. – Drew Sep 26 '16 at 16:15
  • Now the argument can be made that a query with no user data can be `prepare` 'd if for no other reason than to had bindings to php variables on your behalf so as not to go into the row for them. Idk I don't pretend to be a php programmer. But you can't just assume the call to `prepare` succeeds – Drew Sep 26 '16 at 16:21

0 Answers0