При невалидно ID + странициране

nom3r1

Registered
Някой може ли да ми преправи тази заявка да е като хората. Ако може да се добави код при не валидно ID да изкара грешка: ID номера е не валиден или при празен линк като: view.php?get=message&id=
Да излезе "Не сте избрали ID номер.." Също така, ако може да се сложи странициране като това; http://web-tourist.net/forum/viewtopic.php?t=30540 (става на въпрос за странициране като в phpBB)

Код:
case 'message':
	function secure($var) {
	return addslashes(htmlspecialchars($var)); 
	}
	$id = secure($_GET['id']);
		echo "<a href='index.php'>BBoard Forum</a> - <a href='?go=forum&get=post'>Нова тема</a> - <A href='?go=forum&get=reply&id=$id'>Reply</a><br />
			<table class='maintable'>
				<tr class='headline'>
					<td width=20%>Автор</td>
					<td width=80%>Post</td>
				</tr>";
				$query = "SELECT * FROM `posts` WHERE postid='$id'"; //getting topics
				$query2 = mysql_query($query) or die("Could not get topic"); 
					$row = mysql_fetch_array($query2);
						$showtime = $row['shoutime'];
						$author = $row['author'];
						$post = $row['post'];
						echo "
				<tr class='mainrow'>
					<td valign='top'>$author</td>
					<td vakign='top'>Last replied to at $showtime<br><hr>"; 
					$message=strip_tags($post); 
					$message=nl2br($message); 
					echo "$message<hr><br>
					</td>
				</tr>";

				$sql = mysql_query("SELECT * FROM `posts` WHERE parentid='$id' ORDER BY postid ASC"); //getting replies
					while($row2=mysql_fetch_array($sql)) {
						$author = $row2['author'];
						$showtime = $row2['shoutime'];
						$post = $row2['post'];
						echo "
				<tr class='mainrow'>
					<td valign='top'>$author</td>
					<td vakign='top'>Last replied to at $showtime<br><hr>"; 
					$message=strip_tags($post); 
					$message=nl2br($message); 
					echo "$message<hr><br>"; 
					echo "
					</td>
				</tr>"; 
				}

		echo "
			</table>";
break;
 
Пробвай така
case 'message':
function secure($var) {
return addslashes(htmlspecialchars($var));
}
if (!is_numeric($_GET['id'])) { echo "Не сте избрали ID!"; }
else if (!mysql_result(mysql_query("SELECT COUNT(`id`) FROM `posts` WHERE `postid` = '".intval($_GET['id'])."'"),0,0)) { echo "Невалидно ID!"; }
else {
$id = secure($_GET['id']);
echo "<a href='index.php'>BBoard Forum</a> - <a href='?go=forum&get=post'>Нова тема</a> - <A href='?go=forum&get=reply&id=$id'>Reply</a><br />
<table class='maintable'>
<tr class='headline'>
<td width=20%>Автор</td>
<td width=80%>Post</td>
</tr>";
$query = "SELECT * FROM `posts` WHERE postid='$id'"; //getting topics
$query2 = mysql_query($query) or die("Could not get topic");
$row = mysql_fetch_array($query2);
$showtime = $row['shoutime'];
$author = $row['author'];
$post = $row['post'];
echo "
<tr class='mainrow'>
<td valign='top'>$author</td>
<td vakign='top'>Last replied to at $showtime<br><hr>";
$message=strip_tags($post);
$message=nl2br($message);
echo "$message<hr><br>
</td>
</tr>";

$sql = mysql_query("SELECT * FROM `posts` WHERE parentid='$id' ORDER BY postid ASC"); //getting replies
while($row2=mysql_fetch_array($sql)) {
$author = $row2['author'];
$showtime = $row2['shoutime'];
$post = $row2['post'];
echo "
<tr class='mainrow'>
<td valign='top'>$author</td>
<td vakign='top'>Last replied to at $showtime<br><hr>";
$message=strip_tags($post);
$message=nl2br($message);
echo "$message<hr><br>";
echo "
</td>
</tr>";
}

echo "
</table>";
}
break;
 
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/nom3r1/public_html/forum.php on line 131
Невалидно ID!


131 Line:
else if (!mysql_result(mysql_query("SELECT COUNT(`id`) FROM `posts` WHERE `postid` = '".intval($_GET['id'])."'"),0,0)) { echo "Невалидно ID!"; }

По-горе съм си редактирал мнението, ако може да се добави и странициране като това; http://web-tourist.net/forum/viewtopic.php?t=30540 :?:
 

Back
Горе