darkfreaks Posted July 12, 2007 Share Posted July 12, 2007 hey guys i need my code to display the echo rows stuff on the same page below the form table. so the comments would display under it. as well as make the page stuff work with the prev and next links. <? include('connect.php'); include ('func.php'); $datetime=date("y-m-d h:i:s"); //date time $name= $_POST[name]; $email=$_POST[email]; $comment=$_POST[comment]; if ($_POST[email]=="") {$error[email]="please insert an email";} else {unset($error[email]);} if ($_POST[comment]=="") {$error[comment]="please insert a commnet";} else {unset($error[comment]);} if ($_POST[name]=="") {$error[name]="please insert a name";} else {unset($error[name]);} if ($error) { ?> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong> Sign Guestbook </strong></td> </tr> </table> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" > <tr> <form id="form1" name="form1" method="post"> <td> <table width="400" border="0" cellpadding="3" cellspacing="1" > <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><input name="name" type="text" id="name" size="40" /><? if ($_POST) { echo $error[name]; }?> </td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email" size="40" /><? if ($_POST) { echo $error[email]; }?> </td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><textarea name="comment" cols="40" rows="3" id="comment"></textarea> <? if ($_POST) { echo $error[comment]; }?> </td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td> </tr> </table> </td> </form> </tr> </table> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong><a href="guestbook.php">View Guestbook</a> </strong></td> </tr> </table> <? }else{ $message = nl2br($message); $sql="INSERT INTO guestbook(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($sql); $sql="SELECT * FROM guestbook ORDER by id DESC LIMIT $offset, $rowsPerPage"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <? } mysql_close(); //close database} } ?> <? if(mysql_num_rows($result) == 0) { "the guestbook is empty" ;} ?> <? $query = "SELECT COUNT(id) AS numrows FROM guestbook"; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; ?> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td><table width="400" border="0" cellpadding="3" cellspacing="1" > <tr> <td>ID</td> <td>:</td> <td><? echo $rows['id']; ?></td> </tr> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><? echo $rows['name']; ?></td> </tr> <tr> <td>Email</td> <td>:</td> <td><? echo $rows['email']; ?></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><? echo $rows['comment']; ?></td> </tr> <tr> <td valign="top">Date/Time </td> <td valign="top">:</td> <td><? echo $rows['datetime']; ?></td> </tr> </table></td> </tr> </table> <BR> <? // how many guestbook entries to show per page $rowsPerPage = 10; // by default we show first page $pageNum = 1; if(isset($_GET['page'])) { $pageNum = $_GET['page']; } $offset = ($pageNum - 1) * $rowsPerPage; ?> Link to comment https://forums.phpfreaks.com/topic/59576-solved-php-code-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.