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
-Gość_kefir-
post
Post #2





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

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: 7.10.2025 - 00:58