Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MySQL]Problem z bindValue podczas dodawania rekordów do MySQL z użyciem PDO
Raven1122
post
Post #1





Grupa: Zarejestrowani
Postów: 369
Pomógł: 2
Dołączył: 1.11.2010

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


Witam, otoz mam taki problem, że podczas dodawania rekordów mam taki błąd:

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 '' at line 1' in /home/radiolev/public_html/top/index.php:122 Stack trace: #0 /home/radiolev/public_html/top/index.php(122): PDOStatement->execute() #1 {main} thrown in /home/radiolev/public_html/top/index.php on line 122

Kod wygląda następująco:

  1. $author = $_POST['author'];
  2. $title = $_POST['title'];
  3. $link = $_POST['link'];
  4. $addedby = $_POST['addedby'];
  5.  
  6. $stmt = $db->prepare("INSERT INTO radiocms_toplistsongs(`sid`, `author`, `title`, `user`, `ytlink`, `votes`)VALUES('', ?, ?, ?, ?, 0");
  7. $stmt->bindValue(1, $author);
  8. $stmt->bindValue(2, $title);
  9. $stmt->bindValue(3, $addedby);
  10. $stmt->bindValue(4, $ytlink);
  11. $stmt->execute();
  12. header("Location:index.php?action=manage&show=addtomysql&state=success");


oczywiscie polaczenie jest gdzies tam u gory sobie, wiec polaczenie na pewno jest nawiazane.

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
athei
post
Post #2





Grupa: Zarejestrowani
Postów: 389
Pomógł: 141
Dołączył: 11.04.2009

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


No przecież w treści błędu jest wyraźnie napisane, że błąd w zapytaniu.
  1. $stmt = $db->prepare("INSERT INTO radiocms_toplistsongs(`sid`, `author`, `title`, `user`, `ytlink`, `votes`) VALUES ('', ?, ?, ?, ?, 0)");
Go to the top of the page
+Quote Post
Raven1122
post
Post #3





Grupa: Zarejestrowani
Postów: 369
Pomógł: 2
Dołączył: 1.11.2010

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


ale gdzie jest ten blad, bo znalezc nie moge
Go to the top of the page
+Quote Post
Michasko
post
Post #4





Grupa: Zarejestrowani
Postów: 283
Pomógł: 31
Dołączył: 10.01.2006
Skąd: Działoszyn

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


Niedomknięty nawias po VALUES.
Masz:
Kod
")

a powinieneś mieć:
Kod
)")


Ten post edytował Michasko 3.01.2013, 15:38:07
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: 27.09.2025 - 13:54