(Fatal error: call member function bind_param () on a non-object)

I get an error message with this text: (sorry for my poor English I am from Germany!)

Error: Fatal error: Call to a member function bind_param() on a non-object in /users/ftf/www/ccache.php on line 44

Part of the code from ccache.php

  // Neues Datenbank-Objekt erzeugen $db = @new mysqli( 'localhost', 'ftf', '***', 'ftf' ); // Pruefen ob die Datenbankverbindung hergestellt werden konnte if (mysqli_connect_errno() == 0) { $sql = "INSERT INTO cache ('name', 'user', 'veroefentlichung', 'beschreibung', 'FTFcode', 'STFcode', 'TTFcode', 'type', 'lat', 'lon', 'address', 'link') VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?')"; $eintrag = $db->stmt_init(); $eintrag = $db->prepare( $sql ); $eintrag->bind_param($titel, $user, $datum, $desc, $FTF, $STF, $TTF, $type, $Lat, $Lon, $shortdesc, $genlink); // line 44 $eintrag->execute(); // Pruefen ob der Eintrag efolgreich war if ($eintrag->affected_rows == 1) { echo 'Der neue Eintrage wurde hinzugefügt.'; } else { echo 'Der Eintrag konnte nicht hinzugefügt werden.'; } } 
+4
source share
4 answers
  $eintrag->bind_param($titel, $user, $datum, $desc, $FTF, $STF, $TTF, $type, $Lat, $Lon, $shortdesc, $genlink); // line 44 

You need to determine the type of parameters as follows:

 $eintrag->bind_param("ssssssiiss", $titel, $user, $datum, $desc, $FTF, $STF, $TTF, $type, $Lat, $Lon, $shortdesc, $genlink); // line 44 

s - line i - int Also check the documentation: http://php.net/manual/en/mysqli-stmt.bind-param.php

+3
source

Check your return values!

Bad: $eintrag = $db->prepare( $sql )

Good:

 if( ! $eintrag = $db->prepare( $sql ) ) { echo 'Error: ' . $db->error; return false; // throw exception, die(), exit, whatever... } else { // the rest of your code } 

The same goes for $eintrag->execute(); .

Also, the problem is probably you are completing your tags ? in quotation marks. Do not do this. MySQLi does this for you.

+5
source

The error message Call to a member function bind_param() on a non-object ... means that you created the $eintrag object $eintrag before calling bind_params() on it.

This may be because you are trying to create an instance of $eintrag from $db , and this is your line $db = @new mysqli( 'localhost', 'ftf', '***', 'ftf' ); which does not really work.

Try removing the "@", then you can at least read any errors / notifications / warnings:

$db = new mysqli( 'localhost', 'ftf', '***', 'ftf' );

+2
source

Change the code to:

 $sql = "INSERT INTO cache (name, user, veroefentlichung, beschreibung, FTFcode, STFcode, TTFcode, type, lat, lon, 'address', 'link') VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 

(i.e. remove quotes)

+1
source

All Articles