Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Prosty błąd w PDO
Dominator
post 30.05.2013, 15:11:41
Post #1





Grupa: Zarejestrowani
Postów: 565
Pomógł: 15
Dołączył: 11.10.2010

Ostrzeżenie: (20%)
X----


Witam
Dlaczego funkcja nie chce mi dodać rekordów do bazy?

  1. $ilosc = $pdo -> exec("INSERT INTO chat (message, author, data) VALUES ($_message, $_author, $_date)");
  2. if(!$ilosc)
  3. {
  4. echo 'Błąd!';
  5. }


Za każdym razem otrzymuję błąd...
Go to the top of the page
+Quote Post
nospor
post 30.05.2013, 15:16:35
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Wyswietl blad jaki zwraca ci PDO a nie nic nie mowiący komunikat blad :/


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Dominator
post 30.05.2013, 15:20:00
Post #3





Grupa: Zarejestrowani
Postów: 565
Pomógł: 15
Dołączył: 11.10.2010

Ostrzeżenie: (20%)
X----


Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.2013)' at line 1' in D:\xampp\htdocs\Chat\index.php:25 Stack trace: #0 D:\xampp\htdocs\Chat\index.php(25): PDO->exec('INSERT INTO cha...') #1 {main} thrown in
Go to the top of the page
+Quote Post
mmmmmmm
post 30.05.2013, 15:23:40
Post #4





Grupa: Zarejestrowani
Postów: 1 421
Pomógł: 310
Dołączył: 18.04.2012

Ostrzeżenie: (0%)
-----


Podaj wartość parametru $_date
Go to the top of the page
+Quote Post
Dominator
post 30.05.2013, 15:24:51
Post #5





Grupa: Zarejestrowani
Postów: 565
Pomógł: 15
Dołączył: 11.10.2010

Ostrzeżenie: (20%)
X----


  1. $_date = date("d.m.Y");


Ten post edytował Dominator 30.05.2013, 15:25:05
Go to the top of the page
+Quote Post
nospor
post 30.05.2013, 15:35:31
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




1) Wartosci tekstowe w mysql bierze się w apostrofy....
2) Skoro już używasz PDO to zapoznaj się z bindowaniem. Używanie PDO bez bindowanie mija się z celem


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 04:28