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







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

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: 29.06.2026 - 07:17