Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] PDO Delete, jw
miras
post
Post #1





Grupa: Zarejestrowani
Postów: 1 004
Pomógł: 9
Dołączył: 18.01.2011
Skąd: Siedlce

Ostrzeżenie: (30%)
XX---


Witam, mam funkcję, która ma usuwać z bazy pewien rekord.. niestety nie usuwa - co jest nie tak?

  1. public function delete_id($id,$type) {
  2. if ($type=="facebook") {
  3. $this->del = $this->pdo->exec("DELETE FROM `facebook` WHERE `id` = '{$id}'");
  4. } else if ($type=="tv") {
  5. $this->del = $this->pdo->exec("DELETE FROM tv_paczka` WHERE `id` = '{$id}'");
  6. } else if ($type=="galeria") {
  7. $this->del = $this->pdo->exec("DELETE FROM `gallery` WHERE `id` = '{$id}'");
  8. }
  9. if ($this->del) {
  10. header("Location: index.php?page=delete&type=".$type);
  11. }
  12. }


--------------------
Go to the top of the page
+Quote Post
tomxx
post
Post #2





Grupa: Zarejestrowani
Postów: 172
Pomógł: 27
Dołączył: 5.10.2013

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


Spróbuj zamienić każdą linijkę z zapytaniem, np.:
  1. $this->del = $this->pdo->exec("DELETE FROM `facebook` WHERE `id` = '{$id}'");

na:
  1. $this->del = $this->pdo->exec("DELETE FROM `facebook` WHERE `id` = '".$id."'");
Go to the top of the page
+Quote Post
miras
post
Post #3





Grupa: Zarejestrowani
Postów: 1 004
Pomógł: 9
Dołączył: 18.01.2011
Skąd: Siedlce

Ostrzeżenie: (30%)
XX---


Nic to nie dało.


--------------------
Go to the top of the page
+Quote Post
Turson
post
Post #4





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


  1. public function delete_id($id,$type){
  2. if ($type==="facebook") {
  3. $this->type = "facebook";
  4. }
  5. elseif ($type==="tv") {
  6. $this->type = "tv_paczka";
  7. }
  8. elseif ($type==="galeria") {
  9. $this->type = "gallery";
  10. }
  11. $delete = $this->type;
  12. $stmt = $this->pdo->exec("DELETE FROM ".$delete." WHERE `id` = ".$id."");
  13. if ($stmt) {
  14. return true;
  15. }
  16. }


  1. if($obiekt->delete_id($id,$type)){
  2. header("Location: index.php?page=delete&type=".$type);
  3. }


To jest metoda a nie funkcja.
Go to the top of the page
+Quote Post
miras
post
Post #5





Grupa: Zarejestrowani
Postów: 1 004
Pomógł: 9
Dołączył: 18.01.2011
Skąd: Siedlce

Ostrzeżenie: (30%)
XX---


Syntax error or access violation: 1064 Something is wrong in your syntax obok '' w linii 1'

w tym miejscu blad:

  1. $stmt = $this->pdo->exec("DELETE FROM ".$delete." WHERE `id` = ".$id."");


Ok, poradziłem, dzięki.


--------------------
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 Aktualny czas: 20.08.2025 - 13:39