Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP] ShoutBox - Emotikony
Forum PHP.pl > Forum > Przedszkole
bartek4175

Plik shoutbox.php
  1. <?php
  2. require_once("../zapytania.php");
  3. mysql_connect ("mysql3.superhost.pl","sh178151_admin","xxx"); //łącze z bazą ("serwer bazy","użytkownik","hasło")
  4. mysql_select_db ("sh178151_bartek4175"); //nazwa bazy
  5. mysql_query ("SET NAMES utf8"); //kodowanie znaków przydatne przy pobieraniu treści
  6.  
  7. if(isset($_POST['wyslij']) && !empty($_POST['login']) && !empty($_POST['tresc']))
  8. {
  9. //Definicja zmiennych
  10. $login = mysql_real_escape_string(htmlspecialchars($_POST['login']));
  11. $tresc = mysql_real_escape_string(htmlspecialchars($_POST['tresc']));
  12. $data = date('Y-m-d H:i:s');
  13. $ip = $_SERVER['REMOTE_ADDR'];
  14.  
  15. //Wykonujemy zapytanie importujące zdefiniowane dane
  16. mysql_query ("INSERT INTO `posty` (`login`, `tresc`, `data`, `ip`) VALUES('$login', '$tresc', '$data', '$ip')");
  17.  
  18. //No i przenosimy użytkownika z powrotem do shoutboxa
  19. header('Location: '.$_SERVER['REQUEST_URI']);
  20. }
  21. else {
  22. //Pobieramy dane z bazy
  23. $query = mysql_query ("SELECT * FROM `posty` ORDER BY `data` DESC LIMIT 10");
  24.  
  25. //Początek struktury tabeli
  26. echo '<table id="shoutbox">';
  27. //Pętla do wyświetlenia wszystkich wpisów
  28. while($shout=mysql_fetch_array($query)) {
  29. echo '<tr class="wpis"><td>'
  30. .'<b>'.$shout['login'].':</b> ' //wyświetlamy nick
  31. .$shout['tresc'] //wyświetlamy treść
  32. .'<br/><span class="data">'
  33. .$shout['data'] //wyświetlamy datę
  34. .'</span></tr></td>';
  35. } //
  36.  
  37.  
  38. //Koniec struktury tabeli
  39. echo '</table>';
  40. }
  41.  
  42. //print_r($_SERVER);
  43. ?>
  44. <form action="" method="POST" id="shoutbox">
  45. <?php require_once("../zapytania.php"); echo'<input type="hidden" name="login" value="'.$data['login'].'" />'; ?><br/>
  46. Treść: <input type="text" name="tresc" maxlength="125" />
  47. <button type="submit" name="wyslij">Napisz</button>
  48. </form>
  49.  

Plik index.php
  1. OCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>ShoutBox</title>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <link rel="stylesheet" type="text/css" href="styles.css" />
  7. <style type="text/css">
  8. html,body{margin:0;padding:0}
  9. body{ background: #3399FF;
  10. font: 76% arial,sans-serif;text-align:left}
  11. p{margin:0 10px 10px}
  12. a{padding:5px; text-decoration:none; color:#000000;}
  13. #shoutbox { width:100%; font-size: 11px; text-align:left background: green;
  14. }
  15. #shoutbox .wpis { background: #BFBD93; text-align:left}
  16. #shoutbox .data { color: #444; font-size: 10px; }
  17. #shoutbox input { background: #BFBD93; text-align:left border: 1px solid #444; height: 13px; font-size: 11px; }
  18. #shoutbox button { background: #BFBD93; text-align:left border: 1px solid #444; height: 18px; font-size: 11px; }
  19. form { padding-left: 3px; }
  20. </style>
  21. <!--[if lte IE 6]><style type="text/css">#freecssfooter{position:absolute;}</style><![endif]-->
  22. </head>
  23. <body>
  24. <div id="extra">
  25.  
  26. <p><?php include('shoutbox.php'); ?></p>
  27. </div>


Witam! Chciałbym do tego chata dodać emotki:
lol2 - http://emotikona.pl/emotikony/code.php?n=01icon_lol2.gif

: ) ( bez spacji ) - http://firegifts.pl/images/emoticons/wink.gif

Pomocy!
Turson
  1. $string = str_replace(':)', '<img src="http://firegifts.pl/images/emoticons/wink.gif"/>');
bartek4175
Cytat(Turson @ 24.01.2014, 12:27:31 ) *
  1. $string = str_replace(':)', '<img src="http://firegifts.pl/images/emoticons/wink.gif"/>');

tylko gdzie to dać do pliku shoutbox czy to index?
nospor
@Turson zapomniales o trzecim argumencie wink.gif

Gdzie dac? Tam gdzie zamierzasz wyswietlac wiadomosc
bartek4175
Cytat(nospor @ 24.01.2014, 12:34:04 ) *
@Turson zapomniales o trzecim argumencie wink.gif

Gdzie dac? Tam gdzie zamierzasz wyswietlac wiadomosc

Zrobiłem tak:
  1. <?php
  2. require_once("../zapytania.php");
  3. mysql_connect ("mysql3.superhost.pl","xxx","xxxxxx"); //łącze z bazą ("serwer bazy","użytkownik","hasło")
  4. mysql_select_db ("sh178151_bartek4175"); //nazwa bazy
  5. mysql_query ("SET NAMES utf8"); //kodowanie znaków przydatne przy pobieraniu treści
  6.  
  7. if(isset($_POST['wyslij']) && !empty($_POST['login']) && !empty($_POST['tresc']))
  8. {
  9. //Definicja zmiennych
  10. $login = mysql_real_escape_string(htmlspecialchars($_POST['login']));
  11. $tresc = mysql_real_escape_string(htmlspecialchars($_POST['tresc']));
  12. $data = date('Y-m-d H:i:s');
  13. $ip = $_SERVER['REMOTE_ADDR'];
  14.  
  15. //Wykonujemy zapytanie importujące zdefiniowane dane
  16. mysql_query ("INSERT INTO `posty` (`login`, `tresc`, `data`, `ip`) VALUES('$login', '$tresc', '$data', '$ip')");
  17.  
  18. //No i przenosimy użytkownika z powrotem do shoutboxa
  19. header('Location: '.$_SERVER['REQUEST_URI']);
  20. }
  21. else {
  22. //Pobieramy dane z bazy
  23. $query = mysql_query ("SELECT * FROM `posty` ORDER BY `data` DESC LIMIT 10");
  24.  
  25. //Początek struktury tabeli
  26. echo '<table id="shoutbox">';
  27. //Pętla do wyświetlenia wszystkich wpisów
  28. while($shout=mysql_fetch_array($query)) {
  29. echo '<tr class="wpis"><td>'
  30. .'<b>'.$shout['login'].':</b> ' //wyświetlamy nick
  31. .$shout['tresc'] //wyświetlamy treść
  32. .'<br/><span class="data">'
  33. .$shout['data'] //wyświetlamy datę
  34. .'</span></tr></td>';
  35. } //
  36.  
  37.  
  38. //Koniec struktury tabeli
  39. echo '</table>';
  40. }
  41.  
  42. //print_r($_SERVER);
  43. ?>
  44. <form action="" method="POST" id="shoutbox">
  45. <?php require_once("../zapytania.php"); echo'<input type="hidden" name="login" value="'.$data['login'].'" />'; ?><br/>
  46. Treść: <input type="text" name="tresc" maxlength="125" />
  47. <button type="submit" name="wyslij">Napisz</button>
  48. </form>
  49.  
  50. <?
  51. $shout['tresc'] = $txt
  52. $txt = str_replace(':)', '<img src="http://firegifts.pl/images/emoticons/wink.gif"/>');
  53. ?>

wywala:
Parse error: syntax error, unexpected T_VARIABLE in /users/sh178151/www/surfmig.tk/chat/shoutbox.php on line 52

Cytat(Turson @ 24.01.2014, 12:27:31 ) *
  1. $string = str_replace(':)', '<img src="http://firegifts.pl/images/emoticons/wink.gif"/>');

Mam tak:
  1. <?php
  2. require_once("../zapytania.php");
  3. mysql_connect ("mysql3.superhost.pl","sh178151_admin","xxx"); //łącze z bazą ("serwer bazy","użytkownik","hasło")
  4. mysql_select_db ("sh178151_bartek4175"); //nazwa bazy
  5. mysql_query ("SET NAMES utf8"); //kodowanie znaków przydatne przy pobieraniu treści
  6.  
  7. if(isset($_POST['wyslij']) && !empty($_POST['login']) && !empty($_POST['tresc']))
  8. {
  9. //Definicja zmiennych
  10. $login = mysql_real_escape_string(htmlspecialchars($_POST['login']));
  11. $tresc = mysql_real_escape_string(htmlspecialchars($_POST['tresc']));
  12. $data = date('Y-m-d H:i:s');
  13. $ip = $_SERVER['REMOTE_ADDR'];
  14.  
  15. //Wykonujemy zapytanie importujące zdefiniowane dane
  16. mysql_query ("INSERT INTO `posty` (`login`, `tresc`, `data`, `ip`) VALUES('$login', '$tresc', '$data', '$ip')");
  17.  
  18. //No i przenosimy użytkownika z powrotem do shoutboxa
  19. header('Location: '.$_SERVER['REQUEST_URI']);
  20. }
  21. else {
  22. //Pobieramy dane z bazy
  23. $query = mysql_query ("SELECT * FROM `posty` ORDER BY `data` DESC LIMIT 10");
  24.  
  25. //Początek struktury tabeli
  26. echo '<table id="shoutbox">';
  27. //Pętla do wyświetlenia wszystkich wpisów
  28. while($shout=mysql_fetch_array($query)) {
  29. echo '<tr class="wpis"><td>'
  30. .'<b>'.$shout['login'].':</b> ' //wyświetlamy nick
  31. .$shout['tresc'] //wyświetlamy treść
  32. .'<br/><span class="data">'
  33. .$shout['data'] //wyświetlamy datę
  34. .'</span></tr></td>';
  35. } //
  36.  
  37.  
  38. //Koniec struktury tabeli
  39. echo '</table>';
  40. $txt = '.$shout[tresc].';
  41. $txt = str_replace(':)', '<img src="http://firegifts.pl/images/emoticons/wink.gif"/>');
  42. }
  43.  
  44. //print_r($_SERVER);
  45. ?>
  46. <form action="" method="POST" id="shoutbox">
  47. <?php require_once("../zapytania.php"); echo'<input type="hidden" name="login" value="'.$data['login'].'" />'; ?><br/>
  48. Treść: <input type="text" name="tresc" maxlength="125" />
  49. <button type="submit" name="wyslij">Napisz</button>
  50. </form>
  51.  
  52. <?
  53.  
  54. ?>


chat wyświetla ale pod nim jest błąd: Warning: Wrong parameter count for str_replace() in /users/sh178151/www/surfmig.tk/chat/shoutbox.php on line 41
i emotikony nie chodzą
phpion
  1. $txt = str_replace(':)', '<img src="http://firegifts.pl/images/emoticons/wink.gif"/>', $txt);

Jak zauważył ~nospor: ~Turson zapomniał o trzecim argumencie.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.