Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <table>
- <tr>
- <td>
- <h2>Rhettbook</h2>
- <?PHP
- /*here's a challenge for oyu
- make it do pages
- 10 comments per page
- to do that, you'll use LIMIT in your sql query
- LIMIT <offset>,<max>
- so LIMIT 20,10
- at the end of your query
- Jeff: would display comments 20-30
- you'll need to figure out how to set that on the fly depending on what page your on in the comments
- and do paging through $_GET
- so ?pg=2
- would show comments 10-20*/
- $server = 'legionlab.com';
- $username = 'catz';
- $password = '12345';
- $database = 'All_Your_Base_Are_Belong_to_ME';
- date_default_timezone_set('UTC');
- $db = mysql_connect($server, $username, $password, true);
- if(!$db){
- die('The grim reaper is going to come eat you'.mysql_error());
- }
- mysql_select_db($database);
- session_start();
- if(isset($_POST['color'])){
- $color = strip_tags(mysql_real_escape_string($_POST['color']), '<b><u><i><em>');
- $_SESSION['color'] = $color;
- echo '<style type="text/css">
- body{
- background-color:'.$color.';
- }
- </style>';
- }
- if(isset($_POST['sort'])){
- if(isset($_POST['order'])){
- if($_POST['order'] == 'Date'){
- $order = 'id';
- $select0 = ' selected="selected"';
- }else{
- $select0 = '';
- }
- }
- if($_POST['order'] == 'Name'){
- $order = 'name';
- $select1 = ' selected="selected"';
- }else{
- $select1 = '';
- }
- if($_POST['order'] == 'Comment'){
- $order = 'comment';
- $select2 = ' selected="selected"';
- }else{
- $select2 = '';
- }
- if(isset($_POST['updown'])){
- if($_POST['updown'] == 'Ascending'){
- $updown = 'ASC';
- $select3 = ' selected="selected"';
- }else{
- $select3 = '';
- }
- if($_POST['updown'] == 'Descending'){
- $updown = 'DESC';
- $select4 = ' selected="selected"';
- }else{
- $select4 = '';
- }
- }else{
- $updown = 'DESC';
- }
- }else{
- $order = 'id';
- $updown = 'DESC';
- $select0 = '';
- $select1 = '';
- $select2 = '';
- $select3 = '';
- $select4 = '';
- }
- if(isset($_POST['submit'])){
- $comment = strip_tags(mysql_real_escape_string($_POST['comment']), '<b><u><i><em>');
- $name = strip_tags(mysql_real_escape_string($_POST['name']), '<b><u><i><em>');
- if($name == ''){
- $name = 'Anonymous';
- }
- if($comment == ''){
- echo '<b> Enter a comment and/or your name </b><br />';
- }else{
- $sqlcomment = "INSERT INTO Guestbook (comment, name) VALUES ('$comment', '$name')";
- if(mysql_query($sqlcomment)){
- echo '<b> Commented! <br /></b>';
- }
- }
- }
- if(!isset($_GET['pg'])){
- $page = '0';
- }else {
- $page = ($_GET['pg'] - 1) * 10;
- }
- $sqlComDisp = 'SELECT comment, name, timestamp FROM Guestbook ORDER BY '.$order.' '.$updown.' LIMIT '.$page.', 10';
- $comQuery = mysql_query($sqlComDisp);
- //mysql_fetch_assoc();
- //mysql_real_escape_string();
- ?>
- <form method="post" target="_self">
- Comment
- <br />
- <textarea name="comment" rows="5" cols="70"></textarea>
- <br />
- Name:
- <br /><input type="text" maxlength="30" size="30" name="name" />
- <br />
- <input type="submit" name="submit" value="Comment" />
- <br />
- </form>
- <?
- echo '<form method="post" target="_self">
- Sort by
- <select name="order">
- <option',$select0,'>Date</option>
- <option',$select1,'>Name</option>
- <option',$select2,'>Comment</option>
- </select>
- <select name="updown">
- <option',$select3,'>Ascending</option>
- <option',$select4,'>Descending</option>
- </select>
- <input type="submit" name="sort" value="Sort">
- </form>';
- while($commentDisp = mysql_fetch_assoc($comQuery)){
- echo '"'.$commentDisp['comment'].'"','<br />';
- echo '     -', $commentDisp['name'], '<font size="2"> ('.date('F j, Y, g:i a',strtotime($commentDisp['timestamp'])).')</font>';
- echo '<br /><br />';
- }
- ?>
- </td>
- <td align="right" valign="top">
- <form method="post" target="_self" align="right">
- <br /><br /><br /><br /><br />Choose a background color!:
- <br />
- <input type="text" maxlength="10" size="10" name="color" />
- <br />
- <input type="submit" name="colorSubmit" value="Change Color" />
- </form>
- </td>
- </tr>
- </table>
- <a href="<? echo $_SERVER['PHP_SELF'].'?pg='.$_GET['pg']-1; ?>">Previous </a>
- <a href="<? echo $_SERVER['PHP_SELF'].'?pg='.$_GET['pg']+1; ?>"> Next</a>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement