Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP] Problem z zapytaniem do bazy
necromantiq
post 24.07.2011, 14:35:47
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 12.07.2011

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


Siema, napisałem taką oto klasę do insertowania danych do db:

  1. <?php
  2.  
  3. class addNews {
  4.  
  5. public $title;
  6. public $content;
  7. public $author;
  8.  
  9. public function addTitle($title){
  10.  
  11. $this->title = $title;
  12.  
  13. }
  14.  
  15. public function addContent($content){
  16.  
  17. $this->content = $content;
  18.  
  19. }
  20.  
  21. public function addAuthor($author){
  22.  
  23. $this->author = $author;
  24.  
  25. }
  26.  
  27. public function save(){
  28.  
  29. try{
  30.  
  31. require_once('pdo.php');
  32.  
  33. $ins = $pdo->exec('INSERT INTO `news` (`title`, `content`, `author`) VALUES ('$this->title', '$this->content', '$this->author')');
  34. }
  35. catch(PDOExeptions $e){
  36.  
  37. echo 'Wystąpił błąd biblioteki PDO: ' . $e->getMessage();
  38.  
  39. }
  40. }
  41. }
  42. ?>


Lecz non stop wywala mi błąd, Parse error: syntax error, unexpected T_VARIABLE in D:\Projekty\vs\class.addnews.php on line 33 , próbowałem już na różne sposoby i jedynym sukcesem było insertowanie danych jako całego stringa $this->title, $this->content, $this->author. Wiecie może gdzie znajduje się problem??
Go to the top of the page
+Quote Post
skowron-line
post 24.07.2011, 14:44:38
Post #2





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


Czegoś Ci brakuje w tym stringu co go do exec przekazujesz
  1. $ins = $pdo->exec('INSERT INTO `news` (`title`, `content`, `author`) VALUES ('. $this->title .', '. $this->content .', '. $this->author .')');

poczytaj o łączeniu stringów.


--------------------
I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy.

QueryBuilder, Mootools.net, bbcradio1::MistaJam
http://www.phpbench.com/
Go to the top of the page
+Quote Post
necromantiq
post 24.07.2011, 15:13:08
Post #3





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 12.07.2011

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


niestety teraz wywala mi inne błędy:

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 'news, tresc newsa, autor newsa)' at line 1' in D:\Projekty\vs\class.addnews.php on line 33

i drugi błąd:

PDOException: 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 'news, tresc newsa, autor newsa)' at line 1 in D:\Projekty\vs\class.addnews.php on line 33
Go to the top of the page
+Quote Post
amii
post 24.07.2011, 15:21:53
Post #4





Grupa: Zarejestrowani
Postów: 728
Pomógł: 76
Dołączył: 12.06.2009

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


  1. $ins = $pdo->exec("INSERT INTO `news` (`title`, `content`, `author`) VALUES ($this->title, $this->content, $this->author)");

?


--------------------
gry flash online
Dobry hosting i tanie odnowienia domen firma: masternet.
Zarabianie bez wysiłku na domenach bez ruchu: prolink.
Go to the top of the page
+Quote Post
necromantiq
post 24.07.2011, 15:26:20
Post #5





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 12.07.2011

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


no niestety ;/
Go to the top of the page
+Quote Post
lobopol
post 24.07.2011, 17:07:14
Post #6





Grupa: Zarejestrowani
Postów: 1 729
Pomógł: 346
Dołączył: 4.04.2009

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


  1. $ins = $pdo->exec('INSERT INTO `news` (`title`, `content`, `author`) VALUES ("'. $this->title .'", "'. $this->content .'", "'. $this->author .'")');



--------------------
Go to the top of the page
+Quote Post
necromantiq
post 24.07.2011, 17:24:43
Post #7





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 12.07.2011

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


dzieki lobopol smile.gif teraz wszystko śmiga smile.gif
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: 14.08.2025 - 09:04