Call to a member function bind_param() on a non-object

Paperino78

Utente Attivo
30 Giu 2012
409
0
16
Milano
C'è qualcuno che mi sa dire come mai se scrivo questo:
PHP:
$stmt1 = $mysqli->prepare("SELECT * FROM utenti WHERE username= ?, email= ? ");
	    		$stmt1->bind_param("ss", $username, $email);
	    		$stmt1->execute();
	    		$stmt1->store_result();

    			if(($stmt->num_rows > 0) OR ($stmt1->num_rows) > 0){ etc...
mi appare l'errore
PHP:
Call to a member function bind_param() on a non-object
in questa riga
PHP:
$stmt->bind_param('ss', $username, $email);
 

flameseeker

Utente Attivo
27 Nov 2013
699
0
0
La preparazione dello statement è fallita perché la query ha un errore di sintassi.
Dovresti fare così per gestire questo tipo di errori:
PHP:
if ($stmt1 = $mysqli->prepare("SELECT * FROM utenti WHERE username= ? AND email= ? ")) {
                $stmt1->bind_param("ss", $username, $email); 
                $stmt1->execute(); 
                $stmt1->store_result(); 
                etc ...
} else {
    echo 'Hey, qualcosa è andato storto!';
}

(nell'esempio ti ho corretto anche la sintassi dell'istruzione SQL ;))
 

Paperino78

Utente Attivo
30 Giu 2012
409
0
16
Milano
La preparazione dello statement è fallita perché la query ha un errore di sintassi.
Dovresti fare così per gestire questo tipo di errori:
PHP:
if ($stmt1 = $mysqli->prepare("SELECT * FROM utenti WHERE username= ? AND email= ? ")) {
                $stmt1->bind_param("ss", $username, $email); 
                $stmt1->execute(); 
                $stmt1->store_result(); 
                etc ...
} else {
    echo 'Hey, qualcosa è andato storto!';
}

(nell'esempio ti ho corretto anche la sintassi dell'istruzione SQL ;))

Questo il mio codice copleto che purtroppo mi da errore esattamente mi da "NO!" alla riga 15
PHP:
if($stmt1 = $mysqli->prepare("SELECT * FROM utenti WHERE username= ? AND email= ? ")){
	var_dump($stmt1);
$stmt1->bind_param("ss", $username, $email);
$stmt1->execute();
$stmt1->store_result();
$result = $stmt1->num_rows;

if($result > 0){

			while ($row = $stmt1->fetch_assoc())
			{
				echo $row['username'];
			}
		} else {
			echo "NO!";
		}
			
	} else {
		echo "2";
		}
Naturalmente nel database è presente una riga con tutti i dati che mi servono ma qua non li trova!? :incazz:
C'è qualcosa di sbagliato?
 

flameseeker

Utente Attivo
27 Nov 2013
699
0
0
Nello spezzone che hai copiato non ci sono errori, il "NO!" è collegato a questo controllo:
PHP:
if($result > 0){ 
    
} else { 
    echo "NO!"; 
}
Significa che non sono stati trovati record con le clausole di ricerca impostate nella query, di conseguenza forse c'è un errore nel passaggio dei dati: prova a fare var_dump su $username ed $email e verifica se sono corretti.
PHP:
$stmt1->bind_param("ss", $username, $email);
var_dump($username);
var_dump($email);
 

Paperino78

Utente Attivo
30 Giu 2012
409
0
16
Milano
Lo immaginavo anche io. Il punto è che i dati sono corretti. Ma non riesce ad estrarli. Bo. Appena riesco posto il codice di un altro controllo uguale ma fatto in modo diverso.
 

Paperino78

Utente Attivo
30 Giu 2012
409
0
16
Milano
Evitando di usare il codice che ho postato prima, ho cambiato ed ora uso questo, secondo voi va bene?
PHP:
if($result = $mysqli->query("SELECT * FROM utenti ")){

	while($row = $result->fetch_assoc())
	{
		if($email2 == $row['email']){
			//Se è uguale metto in echo la domanda di sicurezza legata alla mail
			echo $row['domanda'];
		} else {
			echo "Email non presente nel nostro Database!";
		}
	}
} $result->close();
 
Discussioni simili
Autore Titolo Forum Risposte Data
L [PHP] Fatal error: Call to a member function prepare() on null in PHP 0
G [RISOLTO][PHP] Call to a member function num_rows() on a non-object PHP 9
A Errore PHP: Call to a member function on null PHP 5
U [PHP] Fatal error: Call to a member function Query() PHP 1
JackIlPazzo Fatal error: Call to a member function execute() on a non-object PHP 2
JackIlPazzo PHP: Fatal error: Call to a member function bind_param() on a non-object PHP 0
P Call to a member function Send() on a non-object PHP 6
T Fatal error: Call to a member function show_crom() on a non-object PHP 1
C [PHP] Errore "Fatal error: Call to undefined function getTotalUsers()" PHP 2
A Errore: cannot call methods on dialog prior to initialization; attempted to call method 'open' jQuery 4
G Fatal error: Uncaught Error: Call to undefined method UserController PHP 0
O Fatal error: Call to undefined function testNome() in C:\xampp\...\...\index.php on line 51 PHP 4
P Fatal error: Call to undefined method SMTP::setTimeout() PHP 4
M fatal error: Call to undefined function gdrcd_filter() PHP 6
F Fatal error: Call to undefined function PHP 9
L Fatal error: Call to undefined method Paging::listaPagine() PHP 2
P Gestione Call Center in java Java 1
D creare "call back"? PHP 2
H Call to undefined function: oci_parse() PHP 0
L Fatal error: Call to undefined function virtual() in C:\Inetpub\wwwroot\... PHP 1
P Call to undefined function mysql_connect() PHP 2
booklisa Ultimate Member — WordPress Plugins - meta dati WordPress 0
O New Member Presenta il tuo Sito 0
K help script member area PHP 0
pacemattia408 disattivazione di una function Javascript 4
W Microsoft OLE DB Provider for Visual FoxPro error '80040e14' Function name is missing ). Classic ASP 0
A [PHP] public static function isEan13 PHP 3
M leggere con jquery/ajax in una function javascript record di database sql server Javascript 0
Y [Javascript] suggerimenti su utilizzo onreadystatechange = function() Javascript 7
Cosina Link in document ready function jQuery 0
B mysql_connect() [function.mysql-connect]: Access denied for user... PHP 13
bubino8 [Javascript] Problema function eseguita solo la prima volta Javascript 1
G [PHP] Problema - Warning: session_start() [function.session-start] PHP 9
V Jquery function find jQuery 7
D Perchè la function non funziona? Javascript 0
F Output html function jQuery 1
felino [JQuery] TypeError: $ is not a function jQuery 1
filippino Fatal error: Cannot redeclare (function) PHP 2
M Function - Class + OOP Javascript 1
K mail() [function mail]: failed to connect to mailserver at localhost port 25 PHP 1
F [RISOLTO]js function per impostare minimo totale Javascript 8
F problemi con $.each(data, function(i,item) e getElementById("livello").innerHTML= Javascript 0
ivarello Function e variabili??? PHP 12
A function conferma Javascript 6
M scope callback function Javascript 1
S Help : Warning: mail() [function.mail] PHP 2
A Navigazione jQuery [era: $(document).ready(function(){] jQuery 3
C Colorare i button con una function Javascript 35
G Problema [function mail] Aruba Hosting 0
V Function ed Array PHP 7

Discussioni simili