0

I wrote two PHP scripts, both of which make a request to my PhpMyAdmin database. The error always occurs with the first script MySQL Database error

"Call to a member function bind_param ()"

on. I know that there are some answers to this on StackOverflow because I have come into contact with this error many times. However, it is now unclear to me why the first script works. I use different tables for this, but I paid attention to primary keys, ...

Edit PHP Code (Error):

$sql_insert=$con->prepare("INSERT INTO Users (Username,Email,Pw,Accounttype,RDate,vkey,Userterms,TFA) VALUES (?,?,?,?,?,?,?,?)");
$sql_insert->bind_param("ssssssss",$un_string,$ea_string,$pw_string_hashed,$acc_string,$date_string,$vkey,$terms,$TFA);
$sql_insert->execute();

The tables look like this: enter image description here

Warning: mysqli::prepare(): Couldn't fetch mysqli in /opt/lampp/htdocs/memeon_data/register.php on line 73

Fatal error: Uncaught Error: Call to a member function bind_param() on bool in /opt/lampp/htdocs/memeon_data/register.php:74 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/memeon_data/register.php on line 74

When I added mysqli_report only the above described and other uninteresting errors occurred.

I only made the two codes for comparison, are now removed again.

Paul T.
  • 4,703
  • 11
  • 25
  • 29
Luca_54
  • 529
  • 4
  • 16
  • `PhpMyAdmin` is a UI, it is not a database. Please add your PHP code, that is where the error is. – user3783243 Jul 22 '20 at 22:57
  • 1
    `mysqli_error($con)` said what? and error reporting? – Funk Forty Niner Jul 22 '20 at 23:02
  • 1
    Why are you including code that works in one table but not the other? – Funk Forty Niner Jul 22 '20 at 23:05
  • Check if you are passing the correct data type, all of them in the prepared statement are strings? – AugustoM Jul 22 '20 at 23:05
  • @AugustoM What isn't a string? – Dharman Jul 22 '20 at 23:06
  • @Dharman Doesn't appear that your duplicate isn't flagged as one. – Funk Forty Niner Jul 22 '20 at 23:09
  • I can easily close this but decided to give the OP a chance to show what the error is and giving them the benefit of the doubt. Something which lacks sometimes here. Edit: *"could have"* now. – Funk Forty Niner Jul 22 '20 at 23:10
  • 1
    @AugustoM The error means that `prepare()` is failing, the datatypes in `bind_param()` are irrelevant. – Barmar Jul 22 '20 at 23:12
  • 1
    @FunkFortyNiner Yeah, but we are not here to help every single person who asks a question. The general advice to enable error reporting is the best one. It's nice of you to wait for OP, but we can close first and then wait, too. :) – Dharman Jul 22 '20 at 23:12
  • @Dharman I felt super friendly today! That could keep going on up until OP's don't answer. Lord knows I try ;-) – Funk Forty Niner Jul 22 '20 at 23:13
  • Ok have checked everything again. There were actually 2 file errors in it. However, the error still occurs. – Luca_54 Jul 22 '20 at 23:18
  • 1
    @LucaKammerer Please, [edit] to add full error message, explain why you have put working code in the question, and tell us what you have done in the meantime. I hope you have put `mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` before `new mysqli` already – Dharman Jul 22 '20 at 23:20
  • 1
    Remove `$con->close()` wherever you can find it in your code. – Dharman Jul 22 '20 at 23:31
  • Ohh that explains a lot. Now it works, thanks :D – Luca_54 Jul 22 '20 at 23:33

0 Answers0