-1

I am having this issue for days now, every SQL command (i am using PDO statements) work except INSERT INTO (i am able to SELECT and CREATE tables, but not to add data from my form into it ). I have checked and I have all the privileges that i need + i have tried all the versions of this code i could find online but nothing seems to work. Any idea? //Sorry for the pic, it's my first post and i did'nt knew.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form method="post"> 
        <input class="input" type= "text" name="nom" placeholder="nom" required> <br>
         <input class="input" type= "password" name="password" placeholder="password" required><br>
         <input class="button" type= "submit" value="Signup"> 
     </form>  <br>
      
</body>
</html>


<?php

//connessione bd
try {
 

  $bd = new PDO("mysql:host=localhost;dbname=ems_db;charset=utf8", "root", "root");
  // set the PDO error mode to exception
 
  
  echo "Connected successfully";
} catch(PDOException $e) {
  echo "Connection failed: " . $e->getMessage();
}


//recupero



$arr['nom'] = $_POST ['nom'];
$arr['password'] = hash('sha1', $_POST ['password']);

print_r($arr);



//

$sql = 'INSERT INTO users ( nom, password) VALUES( :nom, :password,)';

$statement = $bd->prepare($sql);

$statement->execute([
  ':userid' => $arr['userid'],
    ':nom' => $arr['nom'],
    ':password' => $arr['password'],
    ':rankid' => $arr['rankid'],
]);


$publisher_id = $bd->lastInsertId();

echo 'The publisher id ' . $publisher_id . ' was inserted';
Gia
  • 13
  • 2
  • Use [PDOStatement::errorInfo](https://www.php.net/manual/en/pdostatement.errorinfo.php). Also, please post code as text, not as pixels. – KIKO Software Aug 13 '22 at 08:28
  • Please read [Why not upload images of code/errors when asking a question](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) and update your question accordingly. – M. Eriksson Aug 13 '22 at 08:36
  • Have you tried catching exceptions and printing the PDOException message? – Christian Abila Aug 13 '22 at 08:37
  • Post your code as text, not images; add the **complete** text of any error messages you see; take the [tour] you were offered when you posted this question; see [ask] – Tangentially Perpendicular Aug 13 '22 at 08:49
  • Thanks for your Answers and sorry everyone! I did not knew – Gia Aug 13 '22 at 09:27
  • your array of parameters in the `execute` has more key-value pairs (4) than the actual SQL stament requries (2). Also not certain about the last 'virgule' in the SQL statement proper. – YvesLeBorg Aug 13 '22 at 10:40

1 Answers1

-2

to answer your problem, to insert a data, the whole line must be inserted, you can't just insert one data but several data enter image description here

enter image description here

Minat0x
  • 1
  • 2