pagination
Posted: Fri Nov 04, 2011 11:56 am
I have a pagination script and i have run into a small annoying error. When first visiting my page, i encounter an error in red that states "undefined index: page in....". I have about 5 of these, shown below. However, once i click on a page link, it disappears. How do i set it so the error doesnt show at all? Also, what is the best way to do form evaluation? I want to make sure there are no numbers in the name, email in correct format, and no blank fields for name, email or comment. Normally id use an if statement and recreate the form with the appropriate error message nest to the text area. Is there an easier way to do this? Any and all help is greatly appreciated. Thanks.
My form:
Code: Select all
<?php
mysql_connect("localhost","*****","*******");
mysql_select_db("********");
if (isset($_POST['name'])) {
$name=$_POST["name"];
$email=$_POST["email"];
$comment=$_POST["comment"];
$sql="insert into guestbook(name,email,comment)
values('".$name."','".$email."','".$comment."')";
mysql_query($sql,$connection)
or exit("Sql Error".mysql_error());
mysql_close($connection);
}
$perpage = 5;
$lynx = $html = "";
$startat = $_REQUEST['page'] * $perpage;
$q = mysql_query("select count(timenter) from guestbook");
$row = mysql_fetch_array($q);
$pages = ($row[0] + $perpage - 1) / $perpage;
$q = mysql_query("select * from guestbook order by timenter desc limit $startat,$perpage");
while ($row = mysql_fetch_assoc($q)) {
$text = strip_tags($row['comment']);
$text = substr($text,0,300);
$html .= "<dt>$row[name] - <a href=/mouth/$row[name]_.html target=pix>$row[timenter]</a></dt>";
$html .= "<dd>$text ....<br><br></dd>";
};
for ($k=0; $k<$pages; $k++) {
if ($k != $_REQUEST['page']) {
$lynx .= " <a href=test.php"."?page=$k>".($k+1)."</a>";
} else {
$lynx .= " <b>--".($k+1)."--</b>";
}
}
?>Code: Select all
<h1>Guestbook</h1>
<h2>Here are the entries you selected - page <?= $_REQUEST['page']+1 ?>:</h2><br>
<?= $html ?>
Please choose the next page you want to view:
<?= $lynx ?><br /><hr /> <br />
<form action="/~jatindj01/hw2/index.php?" method="post">
<table>
<tr>
<td>Name (Required):</td><td width="180"><input type="text" name="name" /></td>
</tr>
<tr>
<td>E-Mail (will not be published, required):</td><td width="180"><input type="text" name="email" /></td>
</tr>
</table>
<textarea name="comment" rows="10" cols="75"></textarea>
<table><tr>
<td align="center"> <input type="submit" name="submit" value="send" /></td>
</tr></table>
</form>
</div>