PHP: Fatal error: Call to a member function bind_p

2019-09-21 00:16发布

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!

5条回答
做个烂人
2楼-- · 2019-09-21 00:42

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楼-- · 2019-09-21 00:43

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.

查看更多
ら.Afraid
4楼-- · 2019-09-21 00:45

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)

查看更多
做个烂人
5楼-- · 2019-09-21 00:52

...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 !. 
         }
查看更多
趁早两清
6楼-- · 2019-09-21 01:06

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.

查看更多
登录 后发表回答