PDO::errorInfo(): Array ( [0] => 00000 [1] => [2] => )
danipro2110
Messages postés
1
Statut
Membre
-
jordane45 Messages postés 40051 Date d'inscription Statut Modérateur Dernière intervention -
jordane45 Messages postés 40051 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour,
j'ai ce code pour l'insertion des données d'un formulaire d'inscription, je ne sais pas d'ou provient l'erreur,
voila mon code :
<?php
function create_sellerid(){
$length = rand(4,14);
$number = "";
for ($i=0; $i < $length; $i++){
$new_rand = rand(0,9);
$number = $number . $new_rand;
}
return $number;
}
if ($_SERVER['REQUEST_METHOD'] == "POST" )
{
if (!$db = new PDO("mysql:host=localhost;dbname=shopdb","root","dani"))
{
die("cannot connect to database");
}
echo "<pre>";
print_r($_POST);
echo "</pre>";
$arr['seller_id']= create_sellerid();
$arr['compname'] = $_POST['compname'];
$arr['usrname'] = $_POST['usrname'];
$arr['email'] = $_POST['email'];
$arr['birth'] = $_POST['birth'];
$arr['phone'] = $_POST['phone'];
$arr['pswrd'] = hash('sha1' , $_POST['pswrd']);
$query = "insert into sellers (seller_id,compname,usrname,email,birth,phone,pswrd) values (:seller_id,:compname,:usrname,:email,:birth,:phone,:pswrd)";
$stm = $db->prepare($query);
if ($stm)
{
$check = $stm->execute($arr);
if (!$check)
{
echo "\nPDO::errorInfo():\n";
print_r($db->errorInfo());
//echo "error";
}
else
{
header("location : index.php");
}
}
}
?>
j'ai ce code pour l'insertion des données d'un formulaire d'inscription, je ne sais pas d'ou provient l'erreur,
voila mon code :
<?php
function create_sellerid(){
$length = rand(4,14);
$number = "";
for ($i=0; $i < $length; $i++){
$new_rand = rand(0,9);
$number = $number . $new_rand;
}
return $number;
}
if ($_SERVER['REQUEST_METHOD'] == "POST" )
{
if (!$db = new PDO("mysql:host=localhost;dbname=shopdb","root","dani"))
{
die("cannot connect to database");
}
echo "<pre>";
print_r($_POST);
echo "</pre>";
$arr['seller_id']= create_sellerid();
$arr['compname'] = $_POST['compname'];
$arr['usrname'] = $_POST['usrname'];
$arr['email'] = $_POST['email'];
$arr['birth'] = $_POST['birth'];
$arr['phone'] = $_POST['phone'];
$arr['pswrd'] = hash('sha1' , $_POST['pswrd']);
$query = "insert into sellers (seller_id,compname,usrname,email,birth,phone,pswrd) values (:seller_id,:compname,:usrname,:email,:birth,:phone,:pswrd)";
$stm = $db->prepare($query);
if ($stm)
{
$check = $stm->execute($arr);
if (!$check)
{
echo "\nPDO::errorInfo():\n";
print_r($db->errorInfo());
//echo "error";
}
else
{
header("location : index.php");
}
}
}
?>
A voir également:
- Pdo errorinfo 00000
- *#00000# - Guide
- Recording 00000 mp4 - Guide
- Numero 00000 qui m'appelle - Forum Mobile
- Access violation at address 00000 read of address 00000 ✓ - Forum Virus
- Connexion PDO ✓ - Forum PHP
1 réponse
Bonjour
Commence par ça
https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs
Commence par ça
https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs
Si oui.. pas besoin de générer un ID .. ça se fera tout seul.
Et dans ce cas, il ne faut pas spécifier la colonne dans ta requête SQL.
Je précise également que pour sécuriser les mots de passe, on n'utilise plus le sha1 ...
A la place, tourne toi vers la fonction php : password_hash
PS: A l'avenir, pour poster du code sur le forum, merci d'utiliser les balises de code
Explications ( à lire ENTIEREMENT !! ) disponibles ici : https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code