Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP] Problem z zapytaniem do bazy
necromantiq
post
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
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.
Go to the top of the page
+Quote Post
necromantiq
post
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
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)");

?
Go to the top of the page
+Quote Post
necromantiq
post
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
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
Post #7





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

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


dzieki lobopol (IMG:style_emoticons/default/smile.gif) teraz wszystko śmiga (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 21.09.2025 - 10:28