eroare php inserare

Discutii despre tot ce nu se incadreaza in celelalte categorii.

Moderators: Moderatori ajutatori, Moderatori

Post Reply
User avatar
sergiu4995
Membru, skill +4
Membru, skill +4
Posts: 1963
Joined: 08 Oct 2011, 20:05
Detinator Steam: Nu
Has thanked: 27 times
Been thanked: 13 times
Contact:

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();


}
Sigilat.ro
User avatar
The Kalu
eXtream Mod
eXtream Mod
Posts: 12366
Joined: 09 Oct 2010, 11:39
Detinator Steam: Da
Reputatie: Fost membru Club eXtreamCS (6 luni)
Nume anterior: Terra
Has thanked: 199 times
Been thanked: 339 times

24 Mar 2020, 02:05

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'],));

	}

	?>
User avatar
sergiu4995
Membru, skill +4
Membru, skill +4
Posts: 1963
Joined: 08 Oct 2011, 20:05
Detinator Steam: Nu
Has thanked: 27 times
Been thanked: 13 times
Contact:

24 Mar 2020, 13:10

Multumesc frumos :D
User avatar
The Kalu
eXtream Mod
eXtream Mod
Posts: 12366
Joined: 09 Oct 2010, 11:39
Detinator Steam: Da
Reputatie: Fost membru Club eXtreamCS (6 luni)
Nume anterior: Terra
Has thanked: 199 times
Been thanked: 339 times

24 Mar 2020, 15:26

sergiu4995 wrote:
24 Mar 2020, 13:10
Multumesc frumos :D
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.
User avatar
sergiu4995
Membru, skill +4
Membru, skill +4
Posts: 1963
Joined: 08 Oct 2011, 20:05
Detinator Steam: Nu
Has thanked: 27 times
Been thanked: 13 times
Contact:

24 Mar 2020, 20:13

The Kalu wrote:
24 Mar 2020, 15:26
sergiu4995 wrote:
24 Mar 2020, 13:10
Multumesc frumos :D
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.
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
Post Reply

Return to “Discutii generale”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 171 guests