Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: Shoutbox - b³±d
Forum PHP.pl > Forum > PHP
adir
Witam. Jestem nowym urzytkownikiem i mam znikome doswiadczenie w PHP i MySQL.

Oto mój problem:
Na stronie mam shoutbox'a, niestety wy¶wietla siê w nim taki komunikat

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/adir/public_html/ttshout.php on line 194

ttshout.php:

  1. require_once("include/bittorrent.php");
  2. dbconn(false);
  3. loggedinorreturn();
  4.  
  5.  
  6. if ($CURUSER['class'] < UC_USER) 
  7. die();
  8.  
  9. require_once("include/bittorrent.php");
  10. require_once('include/secrets.php');
  11. dbconn(false);
  12. $local_time = get_date_time(time());
  13.  
  14. function MakeSQLSafe($msg)
  15. {
  16.  
  17. //this will allow all punctuation in the message, and also prevent sql injection.
  18.  
  19. $msg = str_replace("'", ''', $msg);
  20. $msg = str_replace("--", '--', $msg);
  21.  
  22. return $msg;
  23. };
  24.  
  25. function MakeHTMLSafe($msg)
  26. {
  27.  
  28. //this will stop people from using javascript and html tags in their posts.
  29.  
  30. $msg = str_replace('<', '<', $msg);
  31. $msg = str_replace('>', '>', $msg);
  32. $msg = str_replace('java script:', 'java script:', $msg);
  33.  
  34. //replace  tags with a proper link
  35. //$msg = preg_replace("/[url]([^[]+)/i","<a href="1" target="_blank">1</a>",$msg);
  36.  
  37. return $msg;
  38. }
  39.  
  40. //deleting msges
  41. if (isset($_GET['del']))
  42. {
  43. //no sql injection
  44. if (is_numeric($_GET['del']))
  45. {
  46. $query = "SELECT * FROM shoutbox WHERE msgid=".$_GET['del'] ;
  47. $result = mysql_query($query);
  48. }
  49. else {echo "invalid msg id STOP TRYING TO INJECT SQL";exit;}
  50.  
  51. $row = mysql_fetch_row($result);
  52.  
  53. if ( (get_user_class() >= UC_MODERATOR) || ($CURUSER['username'] == $row[1]) )
  54. {
  55. $query = "DELETE FROM shoutbox WHERE msgid=".$_GET['del'] ;
  56. mysql_query($query);
  57. }
  58. }
  59.  
  60. //adding msges
  61. if ($_POST['message'] > '')
  62. {
  63.  
  64. if (isset($CURUSER))
  65. {
  66.  
  67. //this will check to see if there has already been an identical message posted (preventing double posts)
  68.  
  69. $query = "SELECT COUNT(*) FROM shoutbox WHERE message='".MakeSQLSafe($_POST['message'])."'";
  70. $result = mysql_query($query);
  71.  
  72. $row = mysql_fetch_row($result);
  73. if ($row[0] == '0')
  74. {
  75.  
  76. //add the message if all is ok. (not a doublepost)
  77. $query = "INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, '".$CURUSER['username']."', '".MakeSQLSafe($_POST['message'])."', '".$local_time."', '".$CURUSER['id']."')";
  78. mysql_query($query);
  79. }
  80. }
  81. }
  82. ?>
  83.  
  84. <HTML>
  85. <HEAD>
  86. <meta http-equiv="Content-type" content="text/html; charset=iso-8859-2">
  87. <TITLE><?=$SITENAME?> Shoutbox</TITLE>
  88. <META HTTP-EQUIV="refresh" content="100">
  89. <link rel="stylesheet" type="text/css" href="ttshout.css" />
  90. </HEAD>
  91.  
  92. <?
  93.  
  94. echo '<BODY style="font-family: verdana; color: black; background-color: #ECE9D8; float: middle" >';
  95.  
  96. ?>
  97.  
  98.  
  99. <script LANGUAGE="JAVASCRIPT">
  100.  
  101. function ShowSmilies() {
  102. var SmiliesWindow = window.open("<?=$SITEURL?>/ttshout_smilies.php", "Smilies","width=250,height=200,resizable=no,scrollbars=no,toolbar=no,location=no,dire
    ctories=no,status=no");
  103. }
  104.  
  105. </SCRIPT>
  106.  
  107. <?
  108.  
  109. if(!isset($_GET['history']))
  110. { 
  111. echo '
  112. <div class="contain">
  113. <table border="0" style="width: 99%; table-layout:fixed">';
  114. }
  115. else
  116. {
  117. echo '
  118. <div class="history">';
  119.  
  120. //page numbers
  121.  
  122. $query = 'SELECT COUNT(*) FROM shoutbox';
  123. $result = mysql_query($query);
  124. $row = mysql_fetch_row($result);
  125. echo '<div align="middle">Pages: ';
  126. $pages = round($row[0] / 100) + 1;
  127. $i = 1;
  128. while ($pages > 0)
  129. {
  130. echo "<a href='".$SITEURL."/ttshout.php?history=1&page=".$i."'>[".$i."]</a> ";
  131. $i++;
  132. $pages--;
  133. }
  134.  
  135. echo '
  136. </div></br><table border="0" style="width: 99%; table-layout:fixed">';
  137. }
  138.  
  139. if (isset($_GET['history']))
  140. {
  141. if (isset($_GET['page']))
  142. {
  143. if($_GET['page'] > '1')
  144. {
  145. $lowerlimit = $_GET['page'] * 100 - 100;
  146. $upperlimit = $_GET['page'] * 100;
  147. }
  148. else
  149. {
  150. $lowerlimit = 0;
  151. $upperlimit = 100;
  152. }
  153. }
  154. else
  155. {
  156. $lowerlimit = 0;
  157. $upperlimit = 100;
  158. }
  159.  
  160. $query = 'SELECT * FROM shoutbox ORDER BY msgid DESC LIMIT '.$lowerlimit.','.$upperlimit;
  161. //echo $query;
  162. }
  163. else
  164. {
  165. $query = 'SELECT * FROM shoutbox ORDER BY msgid DESC LIMIT 10';
  166. }
  167. //echo $query;
  168. $result = mysql_query($query);
  169. $alt = false;
  170.  
  171. while ($row = mysql_fetch_assoc($result)) {
  172.  
  173.  
  174. //alternate the colours
  175. if ($alt)
  176. {
  177. echo '<tr class="noalt">';
  178. $alt = false;
  179. }
  180. else
  181. {
  182. echo '<tr class="alt">';
  183. $alt = true;
  184. }
  185.  
  186. echo '<td style="font-size: 9px; width: 118px;">';
  187. echo "<div align='left' style='float: left'>";
  188.  
  189. echo date('jS M,g:ia',sql_timestamp_to_unix_timestamp($row['date']));
  190.  
  191. echo "</div>";
  192.  
  193.  
  194. $res = mysql_query("SELECT username,class,donor,enabled,warned FROM users WHERE id=$row[userid]");
  195. $arr = mysql_fetch_assoc($res);
  196.  
  197. $url_msg = $row['message'];
  198.  
  199. if ( (get_user_class() >= UC_MODERATOR))
  200. {
  201. echo "<div align='right' style='float: right'><a href='".$SITEURL."/ttshout.php?del=".$row['msgid']."' style='font-size: 8px'>[D]</a><div>";
  202. }
  203.  
  204. switch ($arr["class"]) {
  205.  
  206. case UC_SYSOP:
  207.  $row[user] = "<font color=#990099>$row[user]</font>";
  208.  break;
  209. case UC_ADMINISTRATOR:
  210.  $row[user] = "<font color=#FF0000>$row[user]</font>";
  211.  break;  
  212. case UC_MODERATOR:
  213.  $row[user] = "<font color=#009933>$row[user]</font>";
  214.  break;
  215. case UC_UPLOADER:
  216.  $row[user] = "<font color=#0000B2>$row[user]</font>";
  217.  break;
  218.  case UC_VIP:
  219. $row[user] = "<font color=#2587A7>$row[user]</font>";
  220.  break;
  221.  case UC_POWER_USER:
  222. $row[user] = "<font color=#FFA500>$row[user]</font>";
  223.  break;
  224.  case UC_USER:
  225. $row[user] = "<font color=#000000>$row[user]</font>";
  226.  break;
  227.  case UC_LEECHER:
  228. $row[user] = "<font color=#808000>$row[user]</font>";
  229.  break;
  230. }
  231. echo '</td><td style="font-size: 12px; padding-left: 5px">'.
  232. ($arr["warned"] == "yes" ? "<img src=pic/warned.gif alt=':'>" : "").
  233. ($arr["donor"] == "yes" ? "<img src=pic/star.gif alt=':'>" : "").
  234. ($arr["enabled"] == "no" ? "<img src=pic/disabled.gif alt=':'>" : "").
  235. '<a href="'.$SITEURL.'/userdetails.php?id='.$row['userid'].'" target="_parent"><b>'.
  236. ($arr["class"] == "UC_SYSOP" ? "" : "") .
  237. ($arr["class"] == "UC_ADMINISTRATOR" ? "" : "") .
  238. ($arr["class"] == "UC_MODERATOR" ? "" : "") .
  239. ($arr["class"] == "UC_UPLOADER" ? "" : "") .
  240. ($arr["class"] == "UC_VIP" ? "" : "") .
  241. ($arr["class"] == "UC_POWER_USER" ? "" : "") .
  242. ($arr["class"] == "UC_USER" ? "" : "") .
  243. ($arr["class"] == "UC_LEECHER" ? "" : "") .
  244. '<b>'.$row['user'].'</a>: </b>'
  245. .nl2br(format_shout(MakeHTMLSafe($url_msg)));
  246.  
  247. }
  248.  
  249. echo '</td></tr>';
  250.  
  251. ?>
  252. </table>
  253. </div>
  254. <br>
  255. <?
  256.  
  257. //if the user is logged in, show the shoutbox, if not, dont.
  258. if(!isset($_GET['history']))
  259. {
  260. if (isset($CURUSER))
  261. {
  262.  
  263. echo "
  264. <table style='width: 100%'>
  265. <form name='ttshoutform' action='".$SITEURL."/ttshout.php' method='post'>
  266. <table style='width: 100%'>
  267. <tr class='messageboxback'>
  268. <td width='90%'>
  269. <input type='text' name='message' class='msgbox'>
  270. </td>
  271. <td width='9%'>
  272. <input type='submit' name='submit' value='Krzycz!' class='shoutbtn'>
  273. </td>
  274. </table>
  275.  
  276. <center><a href='".$SITEURL."/ttshout.php'><b><font size=1 color=black>Odswiez</b></a> | </font>
  277. <a href='java script:ShowSmilies();'><b><font size=1 color=black>Smiles</b></a> | </font>
  278. <a href='".$SITEURL."/ttshout.php?history=1' target='_blank'><b><font size=1 color=black>Historia</font></b></a>
  279.  
  280. ";
  281. echo "</form>";
  282. }
  283. else
  284. {
  285.  
  286. echo "<br /><div class='error'>Musisz byæ zalogowowany ¿eby moc pisac na shocie.</div>";
  287.  
  288. }
  289. }
  290.  
  291. ?>
  292. </BODY>
  293. </HTML>


Móg³by mi ktos pomóc w rozwi±zaniu tego problemu?
starach
A masz jakieś wpisy w bazie ?
W ogóle masz tablicę users ?
Wstaw po(chyba 193 linia)
$res = mysql_query("SELECT username,class,donor,enabled,warned FROM users WHERE id=$row[userid]");

$num_rows = mysql_num_rows($result);
die("$num_rows wierszy\n");

edit>
Gdzie masz kod do łączenia się bazą danych ?
Może nie ten skrypt się nie może z bazą połączyć i nawet o tym nie wiesz.
adir
mam w bazie tablice users.
dodalem to co pisa³e¶ i nie pomog³o.

B³±d tego typu wystêpuje jeszcze w kilku innych miejscach u mnie na stronie.
Ta sama strona na yoyo.pl dzialala bez zarzutu, na webd.pl sa z nia problemy
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.