Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Problem z forum
-Gość_kefir-
post
Post #1





Goście







Czy ktos mi pomoze i powie dlaczego posty nie sa dodawane do bazy?

  1. <html>
  2.     <head>
  3.     <title>Forum 3 grupy WSIiE</title>
  4.     </head>
  5.         <body>
  6.         <h2>!! FoRuM DySkuSyJnE  !!</h2>
  7.         <a href="main.php">Wszystkie posty</a>,
  8.         <a href="nowy_post.php">Nowy post</a><hr>
  9.             <?php 
  10.             error_reporting (0);
  11.             //wyswietla formularz i przyjmuje dane, wpisujac nowy post do bazy.
  12.             
  13.             $polaczenie=pg_connect ("host=127.0.0.1 dbname=postgres user=ls password=ddd3") or die ("Nie można połączyć z PostgreSQL");
  14.             
  15.             if ($_POST['co']=='wyslij'){
  16.               $tytul = addslashes(htmlspecialchars ($_POST['tytul']));
  17.               $osoba = addslashes(htmlspecialchars ($_POST['osoba']));
  18.               $tresc = addslashes(nl2br(htmlspecialchars ($_POST['tresc'])));
  19.                   if ($tytul && $osoba && $tresc){ //dopisujemy
  20.                   $zapisz = pg_query("INSERT INTO forum (osoba, tytul , tresc, data, ref) VALUES  ('$osoba', '$tytul', '$tresc', now(),'".$_GET['ref']."')");
  21.                  
  22.                   print 'Wpis został dokonany.<a href="main.php">Księga gości</a>';
  23.                   exit;
  24.                 } else {
  25.                   $tresc2=$_POST['tresc'];
  26.                   $tytul2=$_POST['tytul'];
  27.                   $osoba2=$_POST['osoba'];
  28.                 }
  29.                             
  30.             } elseif ($_GET['ref']>0){
  31.               $wynik = pg_query ($polaczenie, "SELECT osoba, tytul, tresc, data "."FROM forum WHERE nr=".$_GET['ref']);
  32.               if ($wynik && $rekord = pg_fetch_assoc ($wynik)){
  33.                 $tresc = $rekord['tresc']; $tytul = $rekord['tytul'];
  34.                 $tresc = str_replace ("<br />", "", $tresc);
  35.                 $tresc = str_replace ("\n", "\n: ", $tresc); $tresc = ": ".$tresc;
  36.                     if (!(ereg("^Re: ", $tytul))){
  37.                       $tytul = "Re: ".$tytul;
  38.                     }
  39.                     print "<H3>Odpowiedz na post: ".$rekord['tytul']."</H3><P>Wysłany przez ";
  40.                     print "<b>".$rekord['osoba']."</b>,<b>".$rekord['data']."</b></P>".$rekord['tresc']."<br><hr>";
  41.                     
  42.             }
  43.             }
  44.         //grafika od formularza
  45.         
  46.         print "<h3>Wyślij post:</h3>";
  47.         print "<form method=post><input type=\"hidden\" name=\"co\" value=\"";
  48.         print "wyslij\"><input type=\"hidden\" name=\"ref\" value=\"".$_GET['ref']."\">";
  49.         print "<b>Osoba:</b><br><input type=\"text\" name=\"osoba\" ";
  50.         print "<input type=\"text\" name=\"tytul\" value=\"$tytul\" ";
  51.         print "size=60><br><b>tresc:</b><br><textarea name=\"tresc\" ";
  52.         print "rows=10 cols=60>$tresc</textarea><br>\n";
  53.         print "<input type=\"submit\" value=\"Wyslij\">";
  54.         print "</form>";
  55.              ?>
  56.         </body>
  57. </html>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 9)
bigZbig
post
Post #2





Grupa: Zarejestrowani
Postów: 740
Pomógł: 15
Dołączył: 23.08.2004
Skąd: Poznań

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


Napisz co Ci sie wyswietla po wcisnieciu przycisku formularza Wyslij. Poza tym wrtosc zmiennej ref po wyslaniu formularza przekazana jest w zmiennej POST a nie GET dlatego powinno byc

  1. <?php
  2. $zapisz = pg_query('
  3. INSERT INTO forum (osoba, tytul, tresc, data, ref) 
  4. VALUES ('$osoba''$tytul'\$tresc', now(),''.$_POST['ref'].'');
  5. ');  
  6. ?>

cos
Go to the top of the page
+Quote Post
piotrekkr
post
Post #3





Grupa: Zarejestrowani
Postów: 386
Pomógł: 25
Dołączył: 28.09.2005

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


  1. <?php
  2. print "<form method=post><input type=\"hidden\" name=\"co\" value=\"";
  3. ?>

a gdzie jest action="jakis_skrypt.php" (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)

aha i jak chcesz wyrzucic tagi html to uzyj funkcji striptags()

Ten post edytował piotrekkr 22.03.2006, 12:22:29
Go to the top of the page
+Quote Post
kszychu
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 2 712
Pomógł: 23
Dołączył: 27.10.2003
Skąd: z kontowni

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


Cytat(piotrekkr @ 2006-03-22 12:17:56)
a gdzie jest action="jakis_skrypt.php" (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)

Jeżeli w formularzu nie jest podany action, to jest to równoważne takiemu zapisowi:
  1. <?php
  2. echo '<form action="'.$_SERVER['PHP_SELF'].'">';
  3. ?>
Go to the top of the page
+Quote Post
-Gość_kefir-
post
Post #5





Goście







Nic nie pomoglo...

Po nacisnieci Wyslij odswierza sie ta strona lecz nic sie nie dzieje.. nie ma wpisow do bazy, ani komunikatu, ze wpis zostal dodany.. Nie wywala tez bledow..

Nie wiem co jest zle.
Go to the top of the page
+Quote Post
Ociu
post
Post #6





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




Błędów nie ma bo error_reporting powinno być E_ALL.
Go to the top of the page
+Quote Post
pEbE
post
Post #7





Grupa: Zarejestrowani
Postów: 106
Pomógł: 3
Dołączył: 21.03.2006
Skąd: Sosnowiec

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


  1. <?php
  2.  
  3. $data = now(); // zeby bylo wiadomo ;)
  4. $ref = $_GET['ref'];
  5. $zapisz = pg_query("INSERT INTO forum SET osoba='$osoba', tytul='$tytul', tresc='$tresc', data='$data', ref='$ref'");
  6. if(!$zapisz) {
  7. echo pg_result_error($zapisz); // W manualu wyczytalem ze to sluzy do obslugi bledow jednak pewien nie jestem
  8. }
  9. else echo 'Dodano';
  10.  
  11. ?>


Jak mowie nie jestem pewien funkcji pg_result_error wiec jak nie zadziala poszukaj w manualu odpowiedniej...

Ten post edytował pEbE 22.03.2006, 20:02:17
Go to the top of the page
+Quote Post
-Gość_kefir-
post
Post #8





Goście







Poprawilem troche kod.. efekt taki, ze teraz dodaje mi tylko date.. nie mam pojecia co jest nie tak.. POMOZECIE?

  1. <html>
  2. <head>
  3. <title>Forum dyskusyne</title>
  4. </head>
  5. <body>
  6. <h2>Forum dyskusyjne</h2>
  7. <a href="wszystkie.php">Wszystkie posty</a>,<a href="nowy.php">Wyślij nowy post</a><hr>
  8.  
  9. <?php 
  10. //error_reporting (E_ALL);
  11. $polaczenie=pg_connect ("host=127.0.0.1 dbname=postgres user=ls password=ddd3") or die ("Nie można połączyć się z PostgreSQL");
  12. //$ref = $_GET['ref'];
  13. //$data = date("F j, Y, g:i a");;
  14. if ($_POST['co']=='wyslij') {
  15. $ty = addslashes(htmlspecialchars ($_POST['tytul']));
  16. $os = addslashes(htmlspecialchars ($_POST['osoba']));
  17. $tr = addslashes(nl2br(htmlspecialchars ($_POST['tytul'])));
  18. if ($ty && $os && $tr) {
  19. $zapisz = pg_query("INSERT INTO forum (osoba, tytul , tresc, data, ref) VALUES ('$osoba', '$tytul', '$tresc', now(),'".$_GET['ref']."')");
  20.  //pg_query ($zapisz);
  21. print 'Wpis został dokonany. <a href="wszystkie.php">Księga gości</a>';
  22.  exit;
  23. } else {
  24. $tresc = $_POST['tresc'];
  25. $tytul = $_POST['tytyl'];
  26. $osoba = $_POST['osoba'];
  27. }
  28.  
  29. } elseif ($_GET['ref']>0){
  30. $wynik = pg_fetch_result(pg_query ($polaczenie, "SELECT osoba, tytul, tresc, data "."FROM forum WHERE nr=".$_GET['ref']),0);
  31. if ($wynik && $rekord = pgl_fetch_assoc($wynik)){
  32. $tresc = $rekord['tresc']; $tytul = $rekord['tytul']; $tresc =str_replace ("<br />", "", $tresc);
  33. $tresc = str_replace ("\n", "\n: ", $tresc); $tresc = ": ".$tresc;
  34. if (!(ereg("^Re: ", $tytul))){
  35. $tytul = "Re: ".$tytul;
  36. }
  37. print "<h3>Odpowiedz na post: ".$rekord['tytul']."</h3><p>Wysłany przez ";
  38. print "<b>".$rekord['osoba']."</b>,<b>".$rekord['data']."</b></p>".$rekord['tresc']."<br><hr>";
  39. }
  40. }
  41. //formularz
  42. print "<h3>Wyślij post:</h3>";
  43. print "<form method=post><input type=\"hidden\" name=\"co\" value=\"";
  44. print "wyslij\"><input type=\"hidden\" name=\"ref\" value=\"".$_GET['ref']."\">";
  45. print "<b>Osoba:</b><br><input type=\"text\" name=\"osoba\" ";
  46. print "value=\"$osoba\" size=60><br>\n<b>Tytuł postu:</b><br>";
  47. print "<input type=\"text\" name=\"tytul\" value=\"$tytul\" ";
  48. print "size=60><br><b>tresć:</b><br><textarea name=\"tresc\" ";
  49. print "rows=10 cols=60>$tresc</textarea><br>\n";
  50. print "<input type=\"submit\" value=\"Wyślij\">";
  51. print "</form>";
  52.  
  53.  ?>
  54.  
  55. </body>
  56. </html>
Go to the top of the page
+Quote Post
Ociu
post
Post #9





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




  1. <?php
  2. $zapisz = pg_query("INSERT INTO forum (osoba, tytul , tresc, data, ref) VALUES ('$os', '$ty', '$tr', now(),'".$_GET['ref']."')");
  3. ?>

Patrz na zmienne.
Go to the top of the page
+Quote Post
-Gość_kefir-
post
Post #10





Goście







Dziekuje Ci bardzo! Glupi blad... no ale na bledach czlowiek sie uczyc! (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Kolejny problem (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

  1. <html>
  2. <head>
  3. <title>forum</title>
  4. </head>
  5.  
  6. <body>
  7. <h2>forum</h2>
  8. <a href="wszystkie.php">Wszystkie posty</a>, <a href="nowy.php"><Wyślij nowy post</a><hr>
  9.  
  10. <?php 
  11. //error_reporting (E_ALL);
  12.  //wyswietlanie forum, jezeli jest numer postu, to post+odpowiedzi a jesli nie to c
    alosc
  13.  
  14.  function wypiszforum ($nr){
  15.  
  16.  global $fref; global $fdata; global $fosoba; global $ftytul;
  17.  print "<ul>";
  18.  for ($i=count($fref); $i>=1; $i--){
  19.  if ($fref[$i] == $nr) {
  20.  print "<li><a href=\"wszystkie.php?nr=$i\">$ftytul[$i]</a>, "."<i>$fosoba[$i], $fdata[$i]</i>";
  21.  wypiszforum($i);
  22.  }
  23.  }
  24. print "</ul>";
  25. }
  26.  $polaczenie=pg_connect ("host=127.0.0.1 dbname=postgres user=ls password=ddd3") or die ("Nie można połączyć się z PostgreSQL");
  27. if ($nr>0) {
  28. $wynik = pg_fetch_result(pg_query ($polaczenie, "SELECT osoba, tytul, tresc, data "."FROM forum WHERE nr=$nr"),0);
  29. if ($rekord = pg_fetch_array ($wynik)) {
  30. $tresc = $rekord[2]; $tytul = $rekord[1];
  31. print "<h3>$rekord[1]</h3>";
  32. print "<p>wysłany przez <b>$rekord[0]</b>, <b>$rekord[3]</b>:";
  33. print "</p><p>$rekord[2]</p><hr>";
  34. print "<a href=\"nowy.php?ref=$nr\">Wyślij odpowiedź</a><hr>";
  35.  
  36. } else { $nr = 0; 
  37.  
  38. }
  39.  
  40.  
  41. }else{ $nr = 0;}
  42.  
  43. $wynik = pg_fetch_result(pg_query ($polaczenie, "SELECT nr, osoba, tytul, data, ref ". "FROM forum"),0);
  44. while ($rekord = pg_fetch_array ($wynik)){
  45. $fref[$rekord[0]] = $rekord[4];
  46. $fdata[$rekord[0]] = $rekord[3];
  47. $ftytul[$rekord[0]] = $rekord[2];
  48. $fosoba[$rekord[0]] = $rekord[1];
  49.  
  50.  
  51. }
  52. wypiszforum($nr);
  53. ?>
  54. </body>
  55. </html>


Wywala blad Warning: pg_fetch_array() expects parameter 1 to be resource, string given in C:\serwer\www\prace\...............

Pomozecie?
gdzies tu jest blad... ale gdzie?
$wynik = pg_fetch_result(pg_query ($polaczenie, "SELECT nr, osoba, tytul, data, ref ". "FROM forum"),0);
while ($rekord = pg_fetch_array ($wynik))
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: 24.08.2025 - 16:54