Erreur PDOexception que je n'arrive pas à résoudre
Posté : 23 sept. 2019, 08:29
Bonjour je suis entrain d'apprendre à faire un site en php, mais je reçois deux erreurs plutôt embarrassante car je n'arrive pas à les résoudre :
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'id' at row 1 in C:\wamp64\www\Ai-Store\admin\admin.php on line 32
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'id' at row 1 in C:\wamp64\www\Ai-Store\admin\admin.php on line 32
J'ai fais des recherches mais impossible de trouver une solution qui convenait à mon problème, merci d'avance pour votre aide et voici mon code et ma table :
Ma table Phpmyadmin
https://image.noelshack.com/fichiers/20 ... apture.png
Mon code :
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'id' at row 1 in C:\wamp64\www\Ai-Store\admin\admin.php on line 32
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'id' at row 1 in C:\wamp64\www\Ai-Store\admin\admin.php on line 32
J'ai fais des recherches mais impossible de trouver une solution qui convenait à mon problème, merci d'avance pour votre aide et voici mon code et ma table :
Ma table Phpmyadmin
https://image.noelshack.com/fichiers/20 ... apture.png
Mon code :
Code : Tout sélectionner
<link rel="stylesheet" href="style/admin.css">
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<body>
<?php
session_start();
try{
$db = new PDO('mysql:host=127.0.0.1;dbname=ai-store', 'root','');
$db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); // les noms de champs seront en caractères minuscules
$db->setAttribute(PDO::ATTR_ERRMODE , PDO::ERRMODE_EXCEPTION); // les erreurs lanceront des exceptions
}
catch(Exception $e){
die('Une erreur est survenue');
}
if(isset($_SESSION['username'])) {
if(isset($_GET['action'])) {
if($_GET['action']=='add'){
if(isset($_POST['submit'])) {
$title=$_POST['title'];
$description=$_POST['description'];
$price=$_POST['price'];
if($title&&$description&&$price) {
$insert = $db->prepare("INSERT INTO products VALUES('','$title','$description','$price')");
$insert->execute();
}else {
echo'<b><p class="ec">Veuillez remplir tous les champs !</p></b>';
}
}
?>
<form action="" method="post">
<h3>Titre du produit :</h3><input type="text" name="title"/>
<h3>Description :</h3><input type="text" name="description"/>
<h3>Prix :</h3><input type="text" name="price" />
<input type="submit" name="submit"/>
</form>
<?php
}else if($_GET['action']=='modify') {
}else if($_GET['action']=='delete') {
}else {
die('Error');
}
}else{
}
}else{
header('Location: ../index.php');
}
?>
<h1>Bienvenue, <?php echo $_SESSION['username']; ?> !</h1>
<a href="?action=add">Ajouter - Produit</a>
<a href="?action=modify">Modifier - Produit</a>
<a href="?action=delete">Supprimer - Produit</a>
</body>