PHP: Fatal error: Call to a member function bind_param() on a non-object

…衆ロ難τιáo~ 提交于 2019-12-14 03:24:51

问题


The error occurs on line 42:

$result->bind_param("ssssisssss", $Firma, $Partner, $Abteilung, $Strasse, $PLZ, $Ort, $Telefon, $Email, $Website, $Info );

This is the whole prepared statement:

$sql = "INSERT INTO `firmen` (`Firma`, `Ansprechpartner`, `Abteilung`, `Strasse`, `PLZ`, `Ort`, `Telefon`, `Email`, `Website`, `Zusatzinfos`) 
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";     
$result = $db->prepare( $sql ); 
$result->bind_param("ssssisssss", $Firma, $Partner, $Abteilung, $Strasse, $PLZ, $Ort, $Telefon, $Email, $Website, $Info );
$result->execute();

I can't find the mistake, I already read almost every question with the same mistake an I also compared my Code with a lot of Tutorial and it looks exactly the same...

Thanks in advance!


回答1:


...usually this occurs when you have an error in prepare statement, It might happen that you have a typo in sql prepare. to verify that. check the error with this

       $stmt = $this->db->prepare("INSERT INTO ".TB_ADMINISTRATION."(name, password, email) VALUES (?, ?, ?)"); 
       if(!$stmt)  //if there is an error, then it will be shown!. 
         { // show error                                                                                                       
          echo $this->db->error;
          } else {
           // everything is good to go !. 
         }



回答2:


one extra parameters so i removed first parameter: change the following

$result->bind_param("ssssisssss", $Firma, $Partner, $Abteilung, $Strasse, $PLZ, $Ort, $Telefon, $Email, $Website, $Info );

with

$result->bind_param($Firma, $Partner, $Abteilung, $Strasse, $PLZ, $Ort, $Telefon, $Email, $Website, $Info );



回答3:


Here you have you have 10 value in the insert statement

$sql = "INSERT INTO `firmen` (`Firma`, `Ansprechpartner`, `Abteilung`, `Strasse`, `PLZ`, `Ort`, `Telefon`, `Email`, `Website`, `Zusatzinfos`)

and you are giving 11 parameters in the bind->param() like this

$result->bind_param("ssssisssss", $Firma, $Partner, $Abteilung, $Strasse, $PLZ, $Ort, $Telefon, $Email, $Website, $Info );

So you have to corret the number of arguments. So either add another column in the insert statement or remove one value from the bind->param() and keep your insert statement as it is.




回答4:


As the error-message says, $result seems to be not an object. try to debug this by using var_dump($result); right after your prepare-call.

It looks like you're using PHP's PDO. In that case, take a look at the documentation.

If the database server successfully prepares the statement, PDO::prepare() returns a PDOStatement object. If the database server cannot successfully prepare the statement, PDO::prepare() returns FALSE or emits PDOException (depending on error handling).

ALso, what is "sisssssss"? 10 values are needed and you insert 11.

Hm, change this query:

$sql = "INSERT INTO `firmen` (`Firma`, `Ansprechpartner`, `Abteilung`, `Strasse`, `PLZ`, `Ort`, `Telefon`, `Email`, `Website`, `Zusatzinfos`) 
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

Into this:

$sql = "INSERT INTO firmen ('Firma', 'Ansprechpartner', 'Abteilung', 'Strasse', 'PLZ', 'Ort', 'Telefon', 'Email', 'Website', 'Zusatzinfos') 
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

This one ' and ` are not the same.




回答5:


Your error is in the below code

$sql = "INSERT INTO firmen (Firma, Ansprechpartner, Abteilung, Strasse, PLZ, Ort, Telefon, Email, Website, Zusatzinfos)

delete the apostrophe ('') from each as

$sql = "INSERT INTO firmen (Firma, Ansprechpartner, Abteilung, Strasse, PLZ, Ort, Telefon, Email, Website, Zusatzinfos)



来源:https://stackoverflow.com/questions/19244705/php-fatal-error-call-to-a-member-function-bind-param-on-a-non-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!