-1

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);

?>      
Saty
  • 22,213
  • 7
  • 30
  • 49
  • Well, this is as non-interesting as it gets. SO is not a distributed debug service. Please read up on PHP types and how to call PHP functions with typed variables first. What kind of problem are you trying to solve? – StarShine Nov 27 '15 at 07:56
  • error in the query, and then everthing else fails after that, it already says on the error – Kevin Nov 27 '15 at 07:56
  • 1
    `$Eleves` is undefine in your code – Saty Nov 27 '15 at 07:58
  • Indeed, just saw it ! that's why query failed, it's not a variable, it's my table x) – Axel Masson Nov 27 '15 at 08:01

1 Answers1

1

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\n", $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?

Community
  • 1
  • 1
Saty
  • 22,213
  • 7
  • 30
  • 49