Reputation: 43
I have this code in MyFile.php
$db= mysqli_connect("host","user","pw","db");//connect to db
if (mysqli_connect_errno($con))//check connection
{echo "Failed to connect to MySQL: " . mysqli_connect_error();}
//Create a token for the unique link
$title= $_GET[apt_title];
$email= $_GET[mail_address];
$token = sha1(uniqid($email, true));
$time = $_SERVER["REQUEST_TIME"];
//prepare the query to be executed
$query = $db->prepare(
"INSERT INTO pending_users (email, token, title_apt, tstamp) VALUES (?, ?, ?, ?)"
);
$query->execute(
array(
$title,
$email,
$token,
$time
)
);
Error message:
Warning: mysqli_stmt::execute() expects exactly 0 parameters, 1 given in /websites
How should I call execute()
the right way?
Upvotes: 3
Views: 13670
Reputation: 33238
Passing parameters in execute()
is available only as of PHP 8.1. You need to upgrade your PHP version or use the old bind_param()
.
Upvotes: 5
Reputation: 11984
Because mysqli::execute()
does not accept any parameters. Before calling it, you have to prepare the query and then bind the params to the query. Then you have to call the execute()
method. So try like this:
$query = $db->prepare(
"INSERT INTO pending_users (email, token, title_apt) VALUES (?, ?, ?, ?)"
);
$query->bind_param('ssss', $title, $email, $token, $time);
$query->execute();
For more check the documentation
Upvotes: 7
Reputation: 3682
you need to bind params before executing the query, in procedural way do like this
mysqli_stmt_execute($stmt);
if you are doing it like object oriented way after binding params
/* Execute the statement */
$stmt->execute();
Docs link.
http://www.php.net/manual/en/mysqli-stmt.execute.php
Upvotes: 3
Reputation: 19879
If you look at the manual for mysqli::execute(), you'll see that it does not accept any parameters.
bool mysqli_stmt::execute ( void )
Instead, you should use mysqli::bind_param to bind your parameters.
Upvotes: 0