'Warning: mysqli_stmt:: execute() expects exactly 0 parameters, 1 given in
When I post HTML form I am trying to print it to database. It gives the error I mentioned in the title. I couldn't understand because I don't have much knowledge. There is a table named "users" in the database. This table has 4 values. Username, usertag, userphone, name.
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "formusers";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($_POST) {
if ($_POST['submitForm'] == "formSave") {
$username = htmlspecialchars($_POST["username"]);
$usertag = htmlspecialchars($_POST["usertag"]);
$userphone = htmlspecialchars($_POST["userphone"]);
$name = htmlspecialchars($_POST["name"]);
if ($usertag !== '') {
$hextech = $conn->prepare("INSERT INTO users VALUES(NULL,?,?,?,?);");
$hextech->execute([$username, $usertag, $userphone, $name]);
if ($hextech) {
echo '<div class="alert alert-success">
<p>Thanks.</p>
</div>';
//form
} else {
echo '<div class="alert alert-danger">
<p>Some problems.</p>
</div>';
//form
}
} else {
echo 'Required';
}
}
}
Solution 1:[1]
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().
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dharman |
