This question already has an answer here:
i'm facing an issue about my php code, and I don't know how to fix it.
Here are the error messages :
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /var/www/legtux.org/users/blackbeardstudio/www/register.php on line 14
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /var/www/legtux.org/users/blackbeardstudio/www/register.php on line 15
Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in /var/www/legtux.org/users/blackbeardstudio/www/register.php on line 17
And here is the php code :
<?php
$con = mysqli_connect("localhost", "blackbeardstudio" ,"RandomPassword", "blackbeardstudio");
$Nom = $_POST["Nom"];
$age = $_POST["age"];
$Prénom = $_POST["Prénom"];
$mot_de_passe = $_POST["mot_de_passe"];
$Identifiant = $_POST ["identifiant"];
$classe = $_POST ["classe"];
$stmt = mysqli_prepare($con, "INSERT INTO $Eleves (Nom, Prénom, Age, identifiant, mot_de_passe, classe) VALUES (?, ?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, "ssisss", $Nom, $Prénom, $Age, $identifiant, $mot_de_passe, $classe);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
mysqli_close($con);
?>
</div>
AS in your code
$Eleves
is undefined
it will make your query as
INSERT INTO ^^^^^ (Nom, Prénom, Age, identifiant, mot_de_passe, classe) VALUES (?, ?, ?, ?, ?, ?)
It means table name is missing
. You query fails and you got numbers of error
Try to give table name in your query
To check error in your query use
if (!$mysqli->query("SET a=1")) {
printf("Errormessage: %s
", $mysqli->error);
}
Your query is open for sql injection use mysqli_real_escape_string
before insert into database also check How can I prevent SQL injection in PHP?