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:
require_once("include/bittorrent.php");
dbconn(false);
loggedinorreturn();
if ($CURUSER['class'] < UC_USER)
die();
require_once("include/bittorrent.php");
require_once('include/secrets.php');
dbconn(false);
$local_time = get_date_time(time());
function MakeSQLSafe($msg)
{
//this will allow all punctuation in the message, and also prevent sql injection.
$msg = str_replace("'", ''', $msg);
$msg = str_replace("--", '--', $msg);
return $msg;
};
function MakeHTMLSafe($msg)
{
//this will stop people from using javascript and html tags in their posts.
$msg = str_replace('<', '<', $msg);
$msg = str_replace('>', '>', $msg);
$msg = str_replace('java script:', 'java script:', $msg);
//replace tags with a proper link
//$msg = preg_replace("/[url]([^[]+)/i","<a href="1" target="_blank">1</a>",$msg);
return $msg;
}
//deleting msges
if (isset($_GET['del']))
{
//no sql injection
if (is_numeric($_GET['del']))
{
$query = "SELECT * FROM shoutbox WHERE msgid=".$_GET['del'] ;
$result = mysql_query($query);
}
else {echo "invalid msg id STOP TRYING TO INJECT SQL";exit;}
$row = mysql_fetch_row($result);
if ( (get_user_class() >= UC_MODERATOR) || ($CURUSER['username'] == $row[1]) )
{
$query = "DELETE FROM shoutbox WHERE msgid=".$_GET['del'] ;
mysql_query($query);
}
}
//adding msges
if ($_POST['message'] > '')
{
if (isset($CURUSER))
{
//this will check to see if there has already been an identical message posted (preventing double posts)
$query = "SELECT COUNT(*) FROM shoutbox WHERE message='".MakeSQLSafe($_POST['message'])."'";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
if ($row[0] == '0')
{
//add the message if all is ok. (not a doublepost)
$query = "INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, '".$CURUSER['username']."', '".MakeSQLSafe($_POST['message'])."', '".$local_time."', '".$CURUSER['id']."')";
mysql_query($query);
}
}
}
?>
<HTML>
<HEAD>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-2">
<TITLE><?=$SITENAME?> Shoutbox</TITLE>
<META HTTP-EQUIV="refresh" content="100">
<link rel="stylesheet" type="text/css" href="ttshout.css" />
</HEAD>
<?
echo '<BODY style="font-family: verdana; color: black; background-color: #ECE9D8; float: middle" >';
?>
<script LANGUAGE="JAVASCRIPT">
function ShowSmilies() {
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");
}
</SCRIPT>
<?
if(!isset($_GET['history'])) {
<div class="contain">
<table border="0" style="width: 99%; table-layout:fixed">';
}
else
{
<div class="history">';
//page numbers
$query = 'SELECT COUNT(*) FROM shoutbox';
echo '<div align="middle">Pages: '; $pages = round($row[0
] / 100
) + 1; $i = 1;
while ($pages > 0)
{
echo "<a href='".$SITEURL."/ttshout.php?history=1&page=".$i."'>[".$i."]</a> "; $i++;
$pages--;
}
</div></br><table border="0" style="width: 99%; table-layout:fixed">';
}
if (isset($_GET['history'])) {
if (isset($_GET['page'])) {
if($_GET['page'] > '1')
{
$lowerlimit = $_GET['page'] * 100 - 100;
$upperlimit = $_GET['page'] * 100;
}
else
{
$lowerlimit = 0;
$upperlimit = 100;
}
}
else
{
$lowerlimit = 0;
$upperlimit = 100;
}
$query = 'SELECT * FROM shoutbox ORDER BY msgid DESC LIMIT '.$lowerlimit.','.$upperlimit;
//echo $query;
}
else
{
$query = 'SELECT * FROM shoutbox ORDER BY msgid DESC LIMIT 10';
}
//echo $query;
$alt = false;
//alternate the colours
if ($alt)
{
echo '<tr class="noalt">'; $alt = false;
}
else
{
$alt = true;
}
echo '<td style="font-size: 9px; width: 118px;">'; echo "<div align='left' style='float: left'>";
echo date('jS M,g:ia',sql_timestamp_to_unix_timestamp
($row['date']));
$res = mysql_query("SELECT username,class,donor,enabled,warned FROM users WHERE id=$row[userid]");
$url_msg = $row['message'];
if ( (get_user_class() >= UC_MODERATOR))
{
echo "<div align='right' style='float: right'><a href='".$SITEURL."/ttshout.php?del=".$row['msgid']."' style='font-size: 8px'>[D]</a><div>"; }
switch ($arr["class"]) {
case UC_SYSOP:
$row[user] = "<font color=#990099>$row[user]</font>";
break;
case UC_ADMINISTRATOR:
$row[user] = "<font color=#FF0000>$row[user]</font>";
break;
case UC_MODERATOR:
$row[user] = "<font color=#009933>$row[user]</font>";
break;
case UC_UPLOADER:
$row[user] = "<font color=#0000B2>$row[user]</font>";
break;
case UC_VIP:
$row[user] = "<font color=#2587A7>$row[user]</font>";
break;
case UC_POWER_USER:
$row[user] = "<font color=#FFA500>$row[user]</font>";
break;
case UC_USER:
$row[user] = "<font color=#000000>$row[user]</font>";
break;
case UC_LEECHER:
$row[user] = "<font color=#808000>$row[user]</font>";
break;
}
echo '</td><td style="font-size: 12px; padding-left: 5px">'. ($arr["warned"] == "yes" ? "<img src=pic/warned.gif alt=':'>" : "").
($arr["donor"] == "yes" ? "<img src=pic/star.gif alt=':'>" : "").
($arr["enabled"] == "no" ? "<img src=pic/disabled.gif alt=':'>" : "").
'<a href="'.$SITEURL.'/userdetails.php?id='.$row['userid'].'" target="_parent"><b>'.
($arr["class"] == "UC_SYSOP" ? "" : "") .
($arr["class"] == "UC_ADMINISTRATOR" ? "" : "") .
($arr["class"] == "UC_MODERATOR" ? "" : "") .
($arr["class"] == "UC_UPLOADER" ? "" : "") .
($arr["class"] == "UC_VIP" ? "" : "") .
($arr["class"] == "UC_POWER_USER" ? "" : "") .
($arr["class"] == "UC_USER" ? "" : "") .
($arr["class"] == "UC_LEECHER" ? "" : "") .
'<b>'.$row['user'].'</a>: </b>'
.nl2br(format_shout
(MakeHTMLSafe
($url_msg)));
}
?>
</table>
</div>
<br>
<?
//if the user is logged in, show the shoutbox, if not, dont.
if(!isset($_GET['history'])) {
{
<table style='width: 100%'>
<form name='ttshoutform' action='".$SITEURL."/ttshout.php' method='post'>
<table style='width: 100%'>
<tr class='messageboxback'>
<td width='90%'>
<input type='text' name='message' class='msgbox'>
</td>
<td width='9%'>
<input type='submit' name='submit' value='Krzycz!' class='shoutbtn'>
</td>
</table>
<center><a href='".$SITEURL."/ttshout.php'><b><font size=1 color=black>Odswiez</b></a> | </font>
<a href='java script:ShowSmilies();'><b><font size=1 color=black>Smiles</b></a> | </font>
<a href='".$SITEURL."/ttshout.php?history=1' target='_blank'><b><font size=1 color=black>Historia</font></b></a>
";
}
else
{
echo "<br /><div class='error'>Musisz być zalogowowany żeby moc pisac na shocie.</div>";
}
}
?>
</BODY>
</HTML>
Mógłby mi ktos pomóc w rozwiązaniu tego problemu?