Cu msqli merge , dar in pdo nu-mi insereaza in tabel
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'desc,img,date_added,id_sub_category) values('prod','ccc','watch1.jpg','2020-03-2' at line 1
la desc se duce totul e de tip text am pus in tabel
include 'functions.php';
$pdo = pdo_connect_mysql();
try {
$dateTimeZoneLondon = new DateTimeZone("Europe/Bucharest");
$dateTimeLondon = new DateTime("now", $dateTimeZoneLondon);
$londonOffset = $dateTimeZoneLondon->getOffset($dateTimeLondon);
$date_added = date("Y-m-d H:i:s", time() + $londonOffset);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$desc=$_POST['desc'];
$img=$_POST['img'];
$id_sub_category=$_POST['id_sub_category'];
$scat = $pdo->prepare("insert into products(name,desc,img,date_added,id_sub_category) values(:name,:desc,:img,:date_added,:id_sub_category)");
$scat->bindParam(':name', $name);
$scat->bindParam(':desc', $desc);
$scat->bindParam(':img', $img);
$scat->bindParam(':date_added', $date_added);
$scat->bindParam(':id_sub_category', $id_sub_category);
$scat->execute();
}
} catch( PDOEXception $e ) {
echo $e->getMessage();
exit();
}
eroare php inserare
Moderators: Moderatori ajutatori, Moderatori
- sergiu4995
- Membru eXtream
- Posts: 2052
- Joined: 08 Oct 2011, 21:05
- Detinator Steam: Da
- Has thanked: 31 times
- Been thanked: 17 times
- Contact:
-
- Fost administrator
- Posts: 13709
- Joined: 09 Oct 2010, 12:39
- Detinator Steam: Da
- CS Status: In grajd!
- SteamID: kalulord
- Reputatie: Fost Administrator
Fost membru Club eXtreamCS (6 luni)
Nume anterior: Terra - Location: Romania, Ploiesti
- Has thanked: 328 times
- Been thanked: 646 times
- Contact:
Pentru ca il citeste ca si FUNCTIE acel desc, schimba denumirea.Acolo este problema, DESC = DESCENDENT !!!!!
Code: Select all
<?php
//data pentru conectare baza de date
$hostbd = "localhost";
$numebd = "pdo";
$utilizatorbd = "root";
$parolabd = "";
//time zone
$dateTimeZoneLondon = new DateTimeZone("Europe/Bucharest");
$dateTimeLondon = new DateTime("now", $dateTimeZoneLondon);
$londonOffset = $dateTimeZoneLondon->getOffset($dateTimeLondon);
$date_added = date("Y-m-d H:i:s", time() + $londonOffset);
if(isset($_POST['submit'])){
//array date
$valori = Array(
//filtrare date din formular
"nume" => filter_var($_POST['name'], FILTER_SANITIZE_FULL_SPECIAL_CHARS),
"descriere" => filter_var($_POST['descriere'], FILTER_SANITIZE_FULL_SPECIAL_CHARS),
"imagine" => filter_var($_POST['img'], FILTER_SANITIZE_FULL_SPECIAL_CHARS),
"idcategorie" => filter_var($_POST['id_sub_category'], FILTER_VALIDATE_INT)
);
//stabilire conexiune baza de date
$db = new PDO("mysql:host=$hostbd;dbname=$numebd", $utilizatorbd, $parolabd);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$interogare = $db->prepare("INSERT INTO products( name, descriere, img, date_added, id_sub_category) VALUES ( ?, ?, ?, ?, ?)");
$interogare->execute(array($valori['nume'], $valori['descriere'], $valori['imagine'], $date_added, $valori['idcategorie'],));
}
?>
- sergiu4995
- Membru eXtream
- Posts: 2052
- Joined: 08 Oct 2011, 21:05
- Detinator Steam: Da
- Has thanked: 31 times
- Been thanked: 17 times
- Contact:
Multumesc frumos :D
-
- Fost administrator
- Posts: 13709
- Joined: 09 Oct 2010, 12:39
- Detinator Steam: Da
- CS Status: In grajd!
- SteamID: kalulord
- Reputatie: Fost Administrator
Fost membru Club eXtreamCS (6 luni)
Nume anterior: Terra - Location: Romania, Ploiesti
- Has thanked: 328 times
- Been thanked: 646 times
- Contact:
Inca nu ai zis nimic concret, functioneaza sau este partial bin.Data viitoare astept un raspuns mai concret din partea ta daca mai vrei ajutor!!
O zi buna.
- sergiu4995
- Membru eXtream
- Posts: 2052
- Joined: 08 Oct 2011, 21:05
- Detinator Steam: Da
- Has thanked: 31 times
- Been thanked: 17 times
- Contact:
Merge, plus am testat si pana la urma sa las desc adica am scris asa `desc` cu `` si-l insereaza, tu nu gresesti, vii cu solutie care merge.RESPECT