Mysqli_stmt:execute() error

here’s my website:

http://www.bagovanity.great-site.net/registration.php

I have successfully connected to my database but I was having a problem in fixing this part of the code:

Error Message

Warning : mysqli_stmt::execute() expects exactly 0 parameters, 1 given in /home/vol14_1/epizy.com/epiz_32062790/htdocs/registration.php on line 63
ERROR: There was a problem while saving the data.

What is your code on line 63?

3 Likes

I checked your code and see that line 63 contains the following code (actual variable names removed):

$result = $stmtinsert->execute([....]);

At first sight, this is OK. After all, the PHP docs say that you can pass params this way.

However, if you read the documentation more closely, you see that this option was only added with PHP 8.1.0. The latest version of PHP we have is PHP 7.4, which doesn’t have this function parameter.

So instead, you need to use the bind_param() function to bind the parameters to the statement, and then call execute() without any arguments.

So, as taken from the documentation:

$stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
$stmt->bind_param('sssd', $code, $language, $official, $percent);
$stmt->execute();
5 Likes

Alright got it, and it works now. Thank you!

Also I wanna know what ‘sssd’ represents? is it like s for string?

2 Likes

Yes! Here’s the rest from the official php docs:
https://www.php.net/manual/en/mysqli-stmt.bind-param#refsect1-mysqli-stmt.bind-param-parameters

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.