Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Błąd z odbieraniem rekordu z bazy
Komiłaj
post
Post #1





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 10.12.2010

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


Potrzebuję pomocy. Kiedy chcę wyciągnąć rekord z bazy, strona zwraca mi:

BŁĄD Something is wrong in your syntax obok ''strony' WHERE 'id' = 1' w linii 1

(na końcu adresu dodaję ?site=1)
(w header.php skrypt łączy się z bazą)
plik index.php:


  1. <?php
  2. include('includes/header.php');
  3.  
  4. ini_set('display_errors','1');
  5.  
  6. if (!isset($_GET['site']))
  7. $site=1;
  8.  
  9. else
  10. $siteID = mysql_fetch_array(mysql_query("SELECT 'id' FROM 'strony' WHERE 'id' = ".$_GET['site']) or die('BŁĄD '.mysql_error()));
  11. $tresc = mysql_fetch_array(mysql_query("SELECT 'tresc' FROM 'strony' WHERE 'id' = ".$siteID) or die('BŁĄD '.mysql_error()));
  12. $tytul = mysql_fetch_array(mysql_query("SELECT 'tytul' FROM 'strony' WHERE 'id' = ".$siteID) or die('BŁĄD '.mysql_error()));
  13.  
  14. echo ("<b> ".$tytul."</b><br />");
  15. echo $tresc;
  16.  
  17. echo ("<br /><br />");
  18.  
  19. include('includes/footer.php');
  20. ?>
  21.  
  22.  


Przy czym nie widzę tam błędu. Może dlatego, że jestem laikiem (IMG:style_emoticons/default/smile.gif)
Cóż zaradzić?

BTW zrzut bazy:
(IMG:http://axem.az.pl/screenshooter/uploads/o2w9zhijqu7vbm3.jpg)

Ten post edytował Komiłaj 10.12.2010, 23:41:54
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
sadistic_son
post
Post #2





Grupa: Zarejestrowani
Postów: 1 495
Pomógł: 245
Dołączył: 1.07.2009
Skąd: Bydgoszcz

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


1) W 8 linijce masz zmienną $site a potem odwołujesz się do $siteID.
2) Trochę pogmatwałeś z ifami i elsami. Nie powinno być przypadkiem tak?
  1. <?php
  2. include('includes/header.php');
  3.  
  4. ini_set('display_errors','1');
  5.  
  6. if (!isset($_GET['site'])){
  7. $siteID=1;
  8. }
  9. else{
  10. $siteID=$_GET['site'];
  11. }
  12.  
  13. //jaki jest sens poniższego zapytania?! Wyswietl ID gdzie ID = ID ?!? wywal to:
  14. /* $siteID = mysql_fetch_array(mysql_query("SELECT 'id' FROM 'strony' WHERE 'id' = ".$_GET['site']) or die('BŁĄD '.mysql_error())); */
  15.  
  16. $tresc = mysql_fetch_array(mysql_query("SELECT 'tresc' FROM 'strony' WHERE 'id' = ".$siteID) or die('BŁĄD '.mysql_error()));
  17. $tytul = mysql_fetch_array(mysql_query("SELECT 'tytul' FROM 'strony' WHERE 'id' = ".$siteID) or die('BŁĄD '.mysql_error()));
  18.  
  19. //nie mozesz wyswietlac tabli za pomoca echo, no chyba ze w petli. Dlatego zamiast powyzszego czyli $tresc=mysql_fetch... oraz $tytul=mysql_fetch.... proponuję to:
  20. $tresc = mysql_result(mysql_query("SELECT 'tresc' FROM 'strony' WHERE 'id' = ".$siteID." LIMIT 1",0) or die('BŁĄD '.mysql_error()));
  21. $tytul = mysql_result(mysql_query("SELECT 'tytul' FROM 'strony' WHERE 'id' = ".$siteID." LIMIT 1",0) or die('BŁĄD '.mysql_error()));
  22.  
  23. //teraz zadziala ponizsze
  24. echo "<b>$tytul</b><br />";
  25. echo $tresc;
  26.  
  27. echo ("<br /><br />");
  28.  
  29. include('includes/footer.php');
  30. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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: 10.10.2025 - 04:00