Показать сообщение отдельно
Старый 27.01.2004, 17:22     # 1
Folly
Guest
 
Сообщения: n/a

не могу найти ошибку

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/f/folly.h11.ru/WWW/anekdot.php on line 9


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/f/folly.h11.ru/WWW/anekdot.php on line 23




anekdot.php
<?
include 'connect.php';
if (!isset($index)) $index=0;
if (!isset($limit)) $limit=10;
include 'connect.php';
if (!isset($mode)) {
print "<center><b>Êîëëåêöèÿ êîðîòêèõ àíåêäîòîâ</b></center>\n";
$result=mysql_query("select count(id) from anekdot",$db);
$res=mysql_fetch_row($result);
$co=$res[0];
print "<table cellpadding=5><tr><td>\n";
if (!isset($sort)) {
$result=mysql_query("select * from anekdot order by pop desc, enter_date desc limit $index,$limit", $db);
print "<form method='POST' action='$PHP_SELF'><input type='hidden' name='sort' value=1><input type='submit' value='Ñîðòèðîâêà ïî äàòå'></form></td>\n";
}
else {
$result=mysql_query("select * from anekdot order by enter_date desc, pop desc limit $index,$limit", $db);
print "<form method='POST' action='$PHP_SELF'><input type='submit' value='Ñîðòèðîâêà ïî ïîïóëÿðíîñòè'></form></td>\n";
};
print "<td><form method='POST' action='$PHP_SELF'><input type='hidden' name='mode' value='add'><input type='submit' value='Äîáàâèòü ñâîé àíåêäîò'></form></td></table>\n";
print "<table bgcolor=#EFEFEF width=100% border=1 style='text-align: Left; font-size: 10pt; border-style: ridge; border-width: 1' cellspacing=0 cellpadding=0>\n";
$ix=$index;
while ($res=mysql_fetch_array($result)) {
$id=$res['id'];
$url=$res['url'];
$anek=$res['anek'];
$pop=$res['pop'];
$enter_date=$res['enter_date'];
$ix++;
print "<tr><td style='text-align: Left'><b>&nbsp;$ix. </b>$anek</b>\n";
print "<table cellpadding=3 style='font-size: 10pt'><tr><td><b>$enter_date</b></td><td><b><a href='$PHP_SELF?mode=pop&id=$id'>Ïîïóëÿðíîñòü</a>: $pop</b></td><td><b>Äîáàâèë: <a target=_blank href='$url'>$url</a></b></td></tr></table></td></tr>\n";
};
print "</table>\n";
print "<table cellpadding=5><tr>\n";
if ($index > 0) {
$prev=$index-$limit;
if ($prev < 0) $prev=0;
print "<td><form method='POST' action='$PHP_SELF'><input type='hidden' name='index' value=$prev><input type='hidden' name='limit' value=$limit>"; if (isset($sort)) print "<input type='hidden' name='sort' value=1>"; print "<input type='submit' value='Íàçàä'></form></td>\n";
print "<td><form method='POST' action='$PHP_SELF'><input type='hidden' name='index' value=0><input type='hidden' name='limit' value=$limit>"; if (isset($sort)) print "<input type='hidden' name='sort' value=1>"; print "<input type='submit' value=' íà÷àëî'></form></td>\n";
};
if (($index+$limit) < $co) {
$next=$index+$limit;
print "<td><form method='POST' action='$PHP_SELF'><input type='hidden' name='index' value=$next><input type='hidden' name='limit' value=$limit>"; if (isset($sort)) print "<input type='hidden' name='sort' value=1>"; print "<input type='submit' value='Äàëüøå'></form></td>\n";
};
print "</tr></table>\n";
}
else if ($mode=='pop') {
if (!isset($R1)) {
$result=mysql_query("select * from anekdot where id=$id", $db);
$res=mysql_fetch_array($result);
$url=$res['url'];
$anek=$res['anek'];
$pop=$res['pop'];
$enter_date=$res['enter_date'];
print "<center><b>Ïîïóëÿðíîñòü àíåêäîòà</b></center>\n";
print "<blockquote>\n";
print "$anek<br>\n";
print "<br><b>Äîáàâëåí $enter_date <a target=_blank href='$url'>$url</a></b><br>\n";
print "<b>Òåêóùèé ðåéòèíã: $pop</b>\n";
print "<form method='POST' action='$PHP_SELF'><input type='hidden' name='mode' value='pop'><input type='hidden' name='id' value='$id'>\n";
print "<p style='margin: 1'><b><input type='radio' value='plus' name='R1'> +1</b></p>\n";
print "<p style='margin: 1'><b><input type='radio' value='minus' checked name='R1'> -1</b></p>\n";
print "<p style='margin: 1'><input type='submit' value='Ãîëîñîâàòü'></p>\n";
print "</form>\n";
print "</blockquote>\n";
}
else {
$query='';
$s=''.$id;
if ($R1=='plus') $query = 'update anekdot set pop=pop+1 where id='.$s;
else $query = 'update anekdot set pop=pop-1 where id='.$s;
mysql_query($query,$db);
print "<center><b>Îãðîìíîå âàì ÷åëîâå÷åñêîå ñïàñèáî<br>\n";
print "<b>çà ó÷àñòèå â ãîëîñîâàíèè</b>\n";
print "<table cellpadding=5><tr>\n";
print "<td><form method='POST' action='$PHP_SELF'><input type='hidden' name='mode' value='add'><input type='submit' value='Äîáàâèòü ñâîé àíåêäîò'></form></td>\n";
print "<td><form method='POST' action='$PHP_SELF'><input type='submit' value='Âåðíóòüñÿ ê àíåêäîòàì'></form></td>\n";
print "</tr></table></center>\n";
};
}
else if ($mode=='add') {
if (!isset($url) || !isset($anek)) {
print "<center>\n";
print "<p><b>Äîáàâèòü ñâîé àíåêäîò</b></p>\n";
print "<form method='POST' action='$PHP_SELF'>\n";
print "<input type='hidden' name='mode' value='add'>\n";
print "<table cellspacing=3 cellpadding=0>\n";
print "<tr><td><p align=right><b>URL âàøåãî ñàéòà</b></td><td><input type='text' name='url' size=40></td></tr>\n";
print "<tr><td valign=top align=right><p><b>Âàø êîðîòêèé àíåêäîò</b></td><td><textarea rows=4 name='anek' cols=40></textarea></td></tr>\n";
print "<tr><td>&nbsp;</td><td><input type='submit' value='Ãîòîâî'></td></tr></table></form></center>\n";
}
else {
$x = nl2br($anek);
$s = addslashes($x);
$now=date('Y-m-d H:i:s',mktime(gmdate('H')+3,gmdate('i'),gmdate('s'),gmdate('m'),gmdate ('d'),gmdate('Y')));
mysql_query("insert into anekdot (url,anek,pop,enter_date) values ('$url','$s',0,'$now')",$db);
print "<center><b>Îãðîìíîå âàì ÷åëîâå÷åñêîå ñïàñèáî<br>\n";
print "<b>çà äîáàâëåíèå íîâîãî àíåêäîòà</b>\n";
print "<table cellpadding=5><tr>\n";
print "<td><form method='POST' action='$PHP_SELF'><input type='hidden' name='mode' value='add'><input type='submit' value='Äîáàâèòü ñâîé àíåêäîò'></form></td>\n";
print "<td><form method='POST' action='$PHP_SELF'><input type='submit' value='Âåðíóòüñÿ ê àíåêäîòàì'></form></td>\n";
print "</tr></table></center>\n";
};
};
?>


connekt.php
<?
include 'global.php';
$db = mysql_connect($server_name,$user_name,$user_password);
$res=mysql_select_db($db_name,$db);
?>



global.php
<?
$server_name='localhost'; // имя сервера
$user_name='folly8'; // имя пользователя
$user_password=''; // пароль
$db_name='anekdot'; // имя базы
?>