Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]Nie wyświetla
szymon202
post
Post #1





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 13.08.2013

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


Witam (IMG:style_emoticons/default/biggrin.gif) Mam taki kod i według mnie powinien on wyświetlać wartość 1 albo 0 na stronie jednak strona jest cała biała.

Oto kod:
  1. <?php
  2. try {
  3. $db = new PDO('mysql:host=localhost;dbname=furiosmt2;charset=utf8', 'root', 'xxx');
  4. $sql = "SELECT status FROM kody WHERE kod = 1234567890123";
  5. $result = $conn->query($sql);
  6. $f = $q->fetch();
  7. $result = $f['status'];
  8. echo $result;
  9. }
  10. catch(PDOException $e)
  11. {
  12. echo $e->getMessage();
  13. }
  14.  
  15. ?>


A to phpmyadmin:
(IMG:http://screenshu.com/static/uploads/temporary/ce/2a/r9/57mask.jpg)
Go to the top of the page
+Quote Post
maviozo
post
Post #2





Grupa: Zarejestrowani
Postów: 197
Pomógł: 24
Dołączył: 22.11.2010

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


  1. $result = $conn->query($sql);

Co to jest $conn? Nie powinno być $db?
  1. $f = $q->fetch();

Tutaj też $q bierze się znikąd...
Go to the top of the page
+Quote Post
szymon202
post
Post #3





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 13.08.2013

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


To teraz mam taki kod
  1. <?php
  2. try {
  3. $db = new PDO('mysql:host=localhost;dbname=furiosmt2;charset=utf8', 'root', 'xxx');
  4. $sql = "SELECT status FROM kody WHERE kod = 1234567890123";
  5. $result = $db->query($sql);
  6. $f = $sql->fetch();
  7. $result = $f['status'];
  8. echo $result;
  9. }
  10. catch(PDOException $e)
  11. {
  12. echo $e->getMessage();
  13. }
  14.  
  15. ?>


I nadal pusta strona.
Go to the top of the page
+Quote Post
viking
post
Post #4





Grupa: Zarejestrowani
Postów: 6 381
Pomógł: 1116
Dołączył: 30.08.2006

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


Włącz sobie raportowanie błędów. Co to jest? $sql->fetch(); Odwołujesz się do metody fetch na stringu.
Go to the top of the page
+Quote Post
fastlone
post
Post #5





Grupa: Zarejestrowani
Postów: 95
Pomógł: 15
Dołączył: 3.06.2010

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


  1. <?php
  2. try {
  3. $db = new PDO('mysql:host=localhost;dbname=furiosmt2;charset=utf8', 'root', 'xxx');
  4. $sql = "SELECT status FROM kody WHERE kod = 1234567890123";
  5. $result = $db->query($sql);
  6. $f = $result->fetch();
  7. $result = $f['status'];
  8. echo $result;
  9. }
  10. catch(PDOException $e)
  11. {
  12. echo $e->getMessage();
  13. }
  14.  
  15. ?>


@edit
Była pomyłka, poprawiona wersja

Ten post edytował fastlone 23.12.2014, 14:30:03
Go to the top of the page
+Quote Post
szymon202
post
Post #6





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 13.08.2013

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


Działa dzięki.
Go to the top of the page
+Quote Post
Kshyhoo
post
Post #7





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Na przyszłość: Jak poprawnie zadać pytanie.
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: 18.09.2025 - 10:33