eroare php inserare
Posted: 24 Mar 2020, 01:04
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();
}
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();
}