Erreur PDO pendant INSERT INTO
Bonjour tout le monde :D
Dans ma quête du GRAL MySQL je continue à me cogner la tête :aie:
En effet, ce qui fonctionnait 'avant' ne fonctionne plus 'maintenant' :weird:
En gros, je n'arrive pas à insérer car il me dit qu'il y a une erreur de nombre de paramètres... J'ai fait et refait les codes cela ne change strictement rien...
Un regard extérieur peut aider... :)
Voici mes codes :
index.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
Contrat 1and1
<hr>
<?php
include ('../pdo.php');
// AFFICHAGE DONNEES
$sql = 'SELECT numero-client,numero-contrat,user,password FROM 1and1';
try{
$req = $DB->query($sql);
while($d = $req->fetch(PDO::FETCH_ASSOC)){
echo 'Numéro Client : '.$d['numero-client'].'<br \>';
echo 'Numéro de Contrat : '.$d['numero-contrat'].'<br \>';
echo 'ID User : '.$d['user'].'<br \>';
echo 'Mot de Passe : '.$d['password'].'</p>';
echo '<hr>';
}
}
catch(PDOException $e){
echo 'Votre requête a rencontrée une erreur !';
}
?> |
pdo.php
Code:
1 2 3 4 5 6 7 8 9 10 11
|
<?php
// CONNEXION DB
try{
$DB = new PDO('mysql:host=localhost;dbname=dbname','root','');
$DB->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
echo 'La base de donnée n\'est pas disponible!';
}
?> |
form.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>1and1</title>
</head>
<body>
<?php include '../pdo.php';?>
<form method="post" action="insert.php">
Numéro Client : <input type="text" name="numero-client"/><br \><br \>
Numéro Contrat : <input type="text" name="numero-contrat"/><br \><br \>
ID User : <input type="text" name="user"/><br \><br \>
Password : <input type="text" name="password"/><br \><br \>
<input type="submit" value="VALIDER"/>
</form>
</body>
</html> |
et enfin insert.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<!--<meta http-equiv="Refresh" content="0; url=index.php">-->
<title>1and1</title>
</head>
<body>
<?php
include('../pdo.php');
// INSERTION DB
/* données à insérées */
$d = array (
'numero-client' => $_POST['numero-client'],
'numero-contrat' => $_POST['numero-contrat'],
'user' => $_POST['user'],
'password' => $_POST['password'],
);
$req = $DB->prepare('INSERT INTO 1and1 (numero-client,numero-contrat,user,password)
VALUE (:numero-client , :numero-contrat , :user , :password)');
$req->execute($d);
?>
</body>
</html> |