Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Wyszukiwarka na stronie
badowl
post
Post #1





Grupa: Zarejestrowani
Postów: 62
Pomógł: 0
Dołączył: 18.07.2011

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


Witam. Staram się napisać wyszukiwarkę która wyszuka w bazie danych pośród tytułów i artykułów żądaną frazę.
  1. <form method="get" action="<?=$_SERVER['PHP_SELF']?>">
  2. <input type="text" name="word" />
  3. <input type="submit" value="Szukaj" />
  4. </form>
  5. <?php
  6. mysql_connect("localhost", "user", "password") or die(mysql_error());
  7. $keyword = $_GET['word'];
  8. $keyword = trim($keyword);
  9. print "Wyniki wyszukiwania";
  10. $sql = "SELECT title, article FROM tresc WHERE title LIKE $keyword OR article LIKE $keyword";
  11. $result = mysql_query($sql) or die(mysql_error());
  12. while ($row = mysql_fetch_assoc($result)){
  13. print '<a href="wynik.php?id=$row[id]">row[title]</a>';
  14. }
  15. if(mysql_num_rows($result)==0){
  16. print "Brak wynikow!";
  17. }
  18. ?>



Po otworzeniu strony wyświetla się błąd:
"Notice: Undefined index: word in C:\xampp\htdocs\kurs\szukaj.php on line 15
Wyniki wyszukiwaniaYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OR article LIKE' at line 1"

Po wpisaniu słowa które chcę wyszukać wyświetla się:
"Unknown column 'slowo' in 'where clause'"

W czym tkwi problem?
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: 23.08.2025 - 04:21