Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Closed TopicStart new topic
> [MySQL][PHP]unexpected T_STRING
Raven1122
post
Post #1





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

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


Witam. Problem polega na przypisywaniu zmiennej tresco z POST. Cokolwiek bym nie zrobil jest unexpected T_STRING.


Blad:
Parse error: syntax error, unexpected T_STRING in /home/bassplay/public_html/nicco/php/ask.php on line 3

Oto Kod:
  1. <?php
  2. $id = 1;
  3. $subject = '$_POST['subject']';
  4. $content = '$_POST['content']';
  5. $askauthor = '$_POST['nick']';
  6.  
  7.  
  8.  
  9.  
  10. $link = mysql_connect('xxx', 'xxx', 'xxx') or die(mysql_error());
  11. $result = mysql_query($link);
  12. mysql_select_db(bassplay_nicco) or die(mysql_error());
  13.  
  14. $sql = "INSERT INTO blog_asktool(id, subject, question, questionauthor) " .
  15. "VALUES ($id, $subject, $content, $askauthor) ";
  16. $result = mysql_query($sql) or die(mysql_error());
  17. $id = $i++;
  18. echo "Gratulacje";
  19. ?>


Ten post edytował Raven1122 22.08.2011, 09:28:16
Go to the top of the page
+Quote Post
amii
post
Post #2





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

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


Co to za podwójne ciapki ? Tak powinno być:
$subject = $_POST['subject'];

Zaraz mod napisze forum nie parser, to są absolutne podstawy
Go to the top of the page
+Quote Post
skowron-line
post
Post #3





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

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


  1. $subject = '$_POST[\'subject\']';

a jak chcesz zmienną z _POST utworzyć to
  1. $subject = $_POST['subject'];
Go to the top of the page
+Quote Post
Raven1122
post
Post #4





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

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


Juz poprawilem, ale teraz mam blad:
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 ' tak, tak)' at line 1
Go to the top of the page
+Quote Post
skowron-line
post
Post #5





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

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


  1. mysql_select_db(bassplay_nicco) or die(mysql_error());
jeżeli bassplay_nico nie jest stałą to musi być w ciapkach.
  1. $sql = "INSERT INTO blog_asktool(id, subject, question, questionauthor) " .
  2. "VALUES ($id, $subject, $content, $askauthor) ";
  3.  
  4. echo $sql;
i zobacz co się pokazuje. Dodam że musisz w ciapki dać stringi.
Go to the top of the page
+Quote Post
Raven1122
post
Post #6





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

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


Poprawione, i wyskaczyl magiczny blad:
INSERT INTO blog_asktool(id, subject, question, questionauthor) VALUES (1, '', tak', 'tak') 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 '', 'tak')' at line 1
Go to the top of the page
+Quote Post
mortus
post
Post #7





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Masz: INSERT INTO blog_asktool(id, subject, question, questionauthor) VALUES (1, '', tak', 'tak')
A powinno być tak: INSERT INTO blog_asktool(id, subject, question, questionauthor) VALUES (1, '', 'tak', 'tak')
Widzisz różnicę? Kolega skowron-line pisał o tym, że wartości (VALUES) będące łańcuchami znaków należy objąć apostrofami.
Go to the top of the page
+Quote Post
Raven1122
post
Post #8





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

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


Kolejny, Parse error: syntax error, unexpected T_VARIABLE in /home/bassplay/public_html/nicco/php/ask.php on line 16

  1. <?php
  2. $id = 1;
  3. $subject = $_POST['subject'];
  4. $content = $_POST['content'];
  5. $askauthor = $_POST['nick'];
  6. ?>
  7.  
  8.  
  9. <?php
  10.  
  11. $link = mysql_connect('localhost', 'bassplay_nicco', 'ceowwyso12') or die(mysql_error());
  12. $result = mysql_query($link);
  13. mysql_select_db('bassplay_nicco') or die(mysql_error());
  14.  
  15. $sql = "INSERT INTO blog_asktool(id, subject, question, questionauthor) " .
  16. "VALUES ("$id", "$subject", "$content", "$askauthor") ";
  17. $result = mysql_query($sql) or die(mysql_error());
  18. $id = $id++;
  19. echo "Gratulacje";
  20. ?>
Go to the top of the page
+Quote Post
mortus
post
Post #9





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Co Ty robisz? Nie chodzi o to, że zmienne PHP mają być objęte apostrofami, ale o to, że łańcuch znaków, który chcemy wstawić do tabeli bazy danych ma być objęty apostrofami.
  1. // zatem nie
  2. $sql = "INSERT INTO blog_asktool(id, subject, question, questionauthor) " .
  3. "VALUES ("$id", "$subject", "$content", "$askauthor") ";
  4. // a
  5. $sql = "INSERT INTO blog_asktool(id, subject, question, questionauthor) VALUES ($id, '$subject', '$content', '$askauthor')";

Odsyłam do lektury obowiązkowej.
Go to the top of the page
+Quote Post
phpion
post
Post #10





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




Forum to nie parser. Zainstaluj sobie edytor/IDE wyłapujący takie błędy. Zamykam.
Go to the top of the page
+Quote Post

Closed TopicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 05:17