Jump to content

AdamCCFC

Members
  • Posts

    41
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

AdamCCFC's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey guys, do you know why I'm getting this warning?? I'm getting this error on line 186 which is while ($row = mysql_fetch_assoc ($result)) { Here's the rest of my code: <?php $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { /* place table row data in * easier to use variables. * Here we also make sure no * HTML tags, other than the * ones we want are displayed */ $date = $row['date_entered']; $name = htmlentities ($row['name']); $dream = nl2br (strip_tags ($row['dream'], '<a><b><i><u>')); $tags = $row['tags']; /* get number of comments */ $comment_query = "SELECT count(*) FROM dreams_comments WHERE dream_id={$row['dream_id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); /* display number of comments with link */ } } function displayOneItem($id) { global $db; /* query for item */ $query = "SELECT * FROM `dream` WHERE `dream_id` = '$id'"; $result = mysql_query ($query); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "Bad Dream ID\n"; return; } $row = mysql_fetch_assoc($result); /* easier to read variables and * striping out tags */ $name = htmlentities ($row['name']); $dream = nl2br (strip_tags ($row['dream'], '<a><b><i><u>')); $tags = ($row['tags']); ?> <div class='entry'> <span class='link'> <?php echo $row['name']; ?><?php echo " dreamt "; ?><?php echo $row['dream']; ?> </a> </span> </div> <div class='dream_info'> <span class='vote_buttons' id='vote_buttons<?php echo $row['dream_id']; ?>'> <a href='javascript:;' class='vote_up' id='<?php echo $row['dream_id']; ?>'>Vote Up!</a> <a href='javascript:;' class='vote_down' id='<?php echo $row['dream_id']; ?>'>Vote Down!</a> </span> <span class='votes_count' id='votes_count<?php echo $row['dream_id']; ?>'><?php echo $net_vote." votes | "; ?></span> <?php echo "Date submitted: "; ?><?php echo $row['date_entered']; ?><?php echo " | "; ?> <?php /* get number of comments */ $comment_query = "SELECT count(*) FROM dreams_comments WHERE dream_id={$row['dream_id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); echo "<a id='commentslink' href=\"{$_SERVER['PHP_SELF']}?action=show&id={$row['dream_id']}\">Comments ($comment_row[0])</a>";# echo "<br />"; echo " "; /* now show the comments */ displayComments($id); } function displayComments($id) { /* bring db connection variable into scope */ global $db; /* query for comments */ $query = "SELECT * FROM dreams_comments WHERE dream_id=$id"; $result = mysql_query ($query); echo "Comments:</br>"; /* display the all the comments */ while ($row = mysql_fetch_assoc ($result)) { $name = htmlentities ($row['name']); echo "<p class='name'>$name</p>"; $comment = strip_tags ($row['comment'], '<a><b><i><u>'); $comment = nl2br ($comment); echo "<p class='user_comment'>$comment</p>"; echo "</br>"; } /* add a form where users can enter new comments */ echo "Leave a comment!"; echo "</br>"; echo "<form id='addcomment' action=\"" . $_SERVER['PHP_SELF'] . "?action=addcomment&id=$id\" method='POST'>"; echo "<table border='0' width='300'"; echo "<tr><td>Name:</td><td><input type'text' width'30' name='name'></td></tr>"; echo "<tr><td>Comment:</td><td><textarea cols='30' rows='10' name='comment'></textarea></td></tr>"; echo "<tr><td><input type='submit' name='submit' value='Add Comment'</td></tr>"; echo "</form>"; echo "</table>"; } function addComment($id) { global $db; /* insert the comment */ $query = "INSERT INTO dreams_comments VALUES('','$id','$_POST[name]','$_POST[comment]')"; mysql_query($query); echo "Comment entered. Thanks!</br>"; echo "<a href=\"{$_SERVER['PHP_SELF']}?action=show&id=$id\"> Back</a>"; } /* this is where the script decides what do do */ switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayDreams(1); break; case 'addcomment': addComment($_GET['id']); break; default: displayDreams(); } ?>
  2. Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\mydreamz\index.php on line 224?? Here's my code - <?php /** Display the results from the database **/ function displayDreams($all = 0) { /* bring in two variables * $db is our database connection * $max_items is the maximum number * of news items we want to display */ global $db, $max_items; $q = "SELECT * FROM dream ORDER BY date_entered DESC"; $r = mysql_query($q); if(mysql_num_rows($r)>0): //table is non-empty while($row = mysql_fetch_assoc($r)): $net_vote = $row['votes_up'] - $row['votes_down']; //this is the net result of voting up and voting down ?> <div class='entry'> <span class='link'> <?php echo $row['name']; ?><?php echo " dreamt "; ?><?php echo $row['dream']; ?> </a> </span> <span class='vote_buttons' id='vote_buttons<?php echo $row['dream_id']; ?>'> <a href='javascript:;' class='vote_up' id='<?php echo $row['dream_id']; ?>'>Vote Up!</a> <a href='javascript:;' class='vote_down' id='<?php echo $row['dream_id']; ?>'>Vote Down!</a> </span> <span class='votes_count' id='votes_count<?php echo $row['dream_id']; ?>'><?php echo $net_vote." votes"; ?></span> </div> <?php echo $row['tags']; ?><?php echo " "; ?><?php echo $row['date_entered']; ?><?php echo "</br>"; ?> <?php /* get number of comments */ $comment_query = "SELECT count(*) FROM dreams_comments WHERE dream_id={$row['dream_id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); echo "<a id='commentslink' href=\"{$_SERVER['PHP_SELF']}?action=show&id={$row['dream_id']}\">Comments ($comment_row[0])</a>"; ?> <?php endwhile; endif; ?> <?php $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { /* place table row data in * easier to use variables. * Here we also make sure no * HTML tags, other than the * ones we want are displayed */ $date = $row['date_entered']; $name = htmlentities ($row['name']); $dream = nl2br (strip_tags ($row['dream'], '<a><b><i><u>')); $tags = $row['tags']; /* get number of comments */ $comment_query = "SELECT count(*) FROM dreams_comments WHERE dream_id={$row['dream_id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); /* display number of comments with link */ } } function displayOneItem($id) { global $db; /* query for item */ $query = "SELECT * FROM `dream` WHERE `dream_id` = '$id'"; $result = mysql_query ($query); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "Bad Dream ID\n"; return; } $row = mysql_fetch_assoc($result); /* easier to read variables and * striping out tags */ $name = htmlentities ($row['name']); $dream = nl2br (strip_tags ($row['dream'], '<a><b><i><u>')); $tags = ($row['tags']); /* display the items */ echo "<h1>" . $row['name'] . "</h1>"; echo 'dreamt'; echo "<p class='dream'>" . $row['dream'] . "</p>"; echo "<p class='tags'>" . $row['tags'] . "</p>"; echo "<p class='date'>" . $row['date_entered'] . "</p>"; echo "</br>"; /* now show the comments */ displayComments($id); } function displayComments($id) { /* bring db connection variable into scope */ global $db; /* query for comments */ $query = "SELECT * FROM dreams_comments WHERE dream_id=$id"; $result = mysql_query ($query); echo "Comments:</br>"; /* display the all the comments */ while ($row = mysql_fetch_assoc ($result)) { $name = htmlentities ($row['name']); echo "<p class='name'>$name</p>"; $comment = strip_tags ($row['comment'], '<a><b><i><u>'); $comment = nl2br ($comment); echo "<p class='user_comment'>$comment</p>"; echo "</br>"; } /* add a form where users can enter new comments */ echo "Leave a comment!"; echo "</br>"; echo "<form id='addcomment' action=\"" . $_SERVER['PHP_SELF'] . "?action=addcomment&id=$id\" method='POST'>"; echo "<table border='0' width='300'"; echo "<tr><td>Name:</td><td><input type'text' width'30' name='name'></td></tr>"; echo "<tr><td>Comment:</td><td><textarea cols='30' rows='10' name='comment'></textarea></td></tr>"; echo "<tr><td><input type='submit' name='submit' value='Add Comment'</td></tr>"; echo "</form>"; echo "</table>"; } function addComment($id) { global $db; /* insert the comment */ $query = "INSERT INTO dreams_comments VALUES('','$id','$_POST[name]','$_POST[comment]')"; mysql_query($query); echo "Comment entered. Thanks!</br>"; echo "<a href=\"{$_SERVER['PHP_SELF']}?action=show&id=$id\"> Back</a>"; } /* this is where the script decides what do do */ switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayDreams(1); break; case 'addcomment': addComment($_GET['id']); break; default: displayDreams(); } ?> This is line 223 - while ($row = mysql_fetch_assoc ($result)) {
  3. Well I followed tutorials for both, and then I edited it to suite my needs
  4. Right, I've had two scripts that I wanted to merger together. The problem I'm having is that when I click on comments link, all the other dreams in the database are being shown. Can anybody help me?? Here's my code, apologies for how messy it is!! <?php /** Display the results from the database **/ $q = "SELECT * FROM dream"; $r = mysql_query($q); if(mysql_num_rows($r)>0): //table is non-empty while($row = mysql_fetch_assoc($r)): $net_vote = $row['votes_up'] - $row['votes_down']; //this is the net result of voting up and voting down ?> <div class='entry'> <span class='link'> <?php echo $row['name']; ?><?php echo " dreamt "; ?><?php echo $row['dream']; ?> </a> </span> <span class='vote_buttons' id='vote_buttons<?php echo $row['dream_id']; ?>'> <a href='javascript:;' class='vote_up' id='<?php echo $row['dream_id']; ?>'>Vote Up!</a> <a href='javascript:;' class='vote_down' id='<?php echo $row['dream_id']; ?>'>Vote Down!</a> </span> <span class='votes_count' id='votes_count<?php echo $row['dream_id']; ?>'><?php echo $net_vote." votes"; ?></span> </div> <?php echo $row['tags']; ?><?php echo " "; ?><?php echo $row['date_entered']; ?><?php echo "</br>"; ?> <?php /* get number of comments */ $comment_query = "SELECT count(*) FROM dreams_comments WHERE dream_id={$row['dream_id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); echo "<a id='commentslink' href=\"{$_SERVER['PHP_SELF']}?action=show&id={$row['dream_id']}\">Comments ($comment_row[0])</a>"; ?> <?php endwhile; endif; ?> <?php function displayDreams($all = 0) { /* bring in two variables * $db is our database connection * $max_items is the maximum number * of news items we want to display */ global $db, $max_items; //query to display the results $query = "SELECT dream_id,name,dream,tags FROM dream ORDER BY date_entered DESC"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { /* place table row data in * easier to use variables. * Here we also make sure no * HTML tags, other than the * ones we want are displayed */ $date = $row['date_entered']; $name = htmlentities ($row['name']); $dream = nl2br (strip_tags ($row['dream'], '<a><b><i><u>')); $tags = $row['tags']; /* get number of comments */ $comment_query = "SELECT count(*) FROM dreams_comments WHERE dream_id={$row['dream_id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); /* display number of comments with link */ } } function displayOneItem($id) { global $db; /* query for item */ $query = "SELECT * FROM `dream` WHERE `dream_id` = '$id'"; $result = mysql_query ($query); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "Bad Dream ID\n"; return; } $row = mysql_fetch_assoc($result); /* easier to read variables and * striping out tags */ $name = htmlentities ($row['name']); $dream = nl2br (strip_tags ($row['dream'], '<a><b><i><u>')); $tags = ($row['tags']); /* display the items */ echo "<h1>" . $row['name'] . "</h1>"; echo 'dreamt'; echo "<p class='dream'>" . $row['dream'] . "</p>"; echo "<p class='tags'>" . $row['tags'] . "</p>"; echo "<p class='date'>" . $row['date_entered'] . "</p>"; echo "</br>"; /* now show the comments */ displayComments($id); } function displayComments($id) { /* bring db connection variable into scope */ global $db; /* query for comments */ $query = "SELECT * FROM dreams_comments WHERE dream_id=$id"; $result = mysql_query ($query); echo "Comments:</br>"; /* display the all the comments */ while ($row = mysql_fetch_assoc ($result)) { $name = htmlentities ($row['name']); echo "<p class='name'>$name</p>"; $comment = strip_tags ($row['comment'], '<a><b><i><u>'); $comment = nl2br ($comment); echo "<p class='user_comment'>$comment</p>"; echo "</br>"; } /* add a form where users can enter new comments */ echo "Leave a comment!"; echo "</br>"; echo "<form id='addcomment' action=\"" . $_SERVER['PHP_SELF'] . "?action=addcomment&id=$id\" method='POST'>"; echo "<table border='0' width='300'"; echo "<tr><td>Name:</td><td><input type'text' width'30' name='name'></td></tr>"; echo "<tr><td>Comment:</td><td><textarea cols='30' rows='10' name='comment'></textarea></td></tr>"; echo "<tr><td><input type='submit' name='submit' value='Add Comment'</td></tr>"; echo "</form>"; echo "</table>"; } function addComment($id) { global $db; /* insert the comment */ $query = "INSERT INTO dreams_comments VALUES('','$id','$_POST[name]','$_POST[comment]')"; mysql_query($query); echo "Comment entered. Thanks!</br>"; echo "<a href=\"{$_SERVER['PHP_SELF']}?action=show&id=$id\"> Back</a>"; } /* this is where the script decides what do do */ switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayDreams(1); break; case 'addcomment': addComment($_GET['id']); break; default: displayDreams(); } ?>
  5. This is line 64 btw - $old_stats=file($ficdest);
  6. Hey guys, I'm trying to get a simple good/bad voting system on my website. I've used a free script but I'm getting this warning - Warning: file() [function.file]: Filename cannot be empty in C:\xampp\htdocs\mydreamz\vote\vote.php on line 64 Above that I'm also seeing - Thank you for voting"; } else { echo "You have already voted"; $vote=fopen($ficdest, "w"); $new_stats=fputs($vote, "$stats[0]|$stats[1]|$stats[2]|$ip|"); fclose($vote); } } ?> Here's the code - <STYLE type=text/css> TD { COLOR: #000000; FONT-FAMILY: Verdana, Helvetica, Arial; FONT-SIZE: 11px } </style> <? extract($HTTP_GET_VARS); extract($HTTP_POST_VARS); /********* PHP Voting SYSTEM v1.0 ************ Copyright 2007, Scriptsez.net You have to leave the copyright. If you have any problem just let us know. Website: http://www.scriptsez.net **********************************************/ $ficdest1=explode(".",basename($PHP_SELF)); $ficdest="vote/".$ficdest1[0].".dat"; $ip = getenv(REMOTE_ADDR); if(file_exists($ficdest)) { $compteur=fopen($ficdest, "r"); $old_stats=file($ficdest); $stats=explode("|", $old_stats[0]); fclose($compteur); $new_count=$stats[0]; $ip_hit=$ip; } else { $nouveau_compteur=fopen($ficdest, "w"); fputs($nouveau_compteur, "0|0|0|0|"); fclose($nouveau_compteur); } if (!empty($envoi)&& $note !="") { $vote=fopen($ficdest, "r"); $old_stats=file($ficdest); $stats=explode("|", $old_stats[0]); fclose($vote); $nbr_votes=$stats[0]; $moy_votes=$stats[1]; if ($stats[3] != $ip) { $new_count = $stats[0]+1; if($note=="Good"){ $moy_votes1=$moy_votes+1; $statical=$stats[2]; }elseif($note=="Bad"){ $statical=$stats[2]+1; $moy_votes1=$moy_votes; } $vote=fopen($ficdest, "w"); $new_stats=fputs($vote, "$new_count|$moy_votes1|$statical|$ip|"); fclose($vote); echo "<font face=Verdana size=2 color=blue>Thank you for voting</font>"; } else { echo "<font face=Verdana size=2 color=red>You have already voted</font>"; $vote=fopen($ficdest, "w"); $new_stats=fputs($vote, "$stats[0]|$stats[1]|$stats[2]|$ip|"); fclose($vote); } } ?> <!-- Copyright Scriptsez.net Visit http://www.scriptsez.net to get this script for Free --> <?php print ("<form method=post>"); $old_stats=file($ficdest); $stats=explode("|", $old_stats[0]); $total=($stats[1]+$stats[2]); if($total<="0"){ $total="1"; $mtotal="Not yet voted"; }else{ if($total=="1"){$spell="vote";}else{$spell="votes";} $mtotal="$total $spell"; } $gpercentage=(($stats[1]/$total)*1000); $goodp=round(($gpercentage / 10 * 10))/10; $bpercentage=(($stats[2]/$total)*1000); $badp=round(($bpercentage / 10 * 10))/10; echo "<table><tr><td><img src=images/thumbs_up.gif>$goodp %</td><td> </td><td><img src=images/thumbs_down.gif>$badp %</td><td>[$mtotal]</td></tr></table>"; echo"<table><tr><td align=center><img src=images/thumbs_up.gif></td><td><input type=radio name=note value=Good>Good</td>"; echo"<td align=center><img src=images/thumbs_down.gif></td><td><input type=radio name=note value=Bad>Bad</td>"; print ("<td><input type=hidden name=envoi value=1><input type=submit value=Vote style=background:#ffcc00;border-width:1;Border-color:#ffcc00;></td></tr></table></form></font>"); ?> Does anybody know why I am getting this, and how I can solve it? Any help would be greatly appreciated!
  7. The page is showing all the results from my database, then when the link to go to the second page is clicked the same results are being displayed on that page. I have basically merged two scripts together. I had the paination working showing the results, but that was before I had the comment system in place. When I put the script of the comment system with the pagination script, it stopped working properly. Any help would be greatly appreciated! Thanks in advanced, Adam! Here's my code <?php include('connect.php'); $tableName="dream"; $targetpage = "index.php"; $limit = 5; $query = "SELECT COUNT(*) as num FROM $tableName ORDER BY `date_entered` DESC"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; $stages = 3; $page = mysql_escape_string($_GET['page']); if($page){ $start = ($page - 1) * $limit; }else{ $start = 0; } // Get page data $query1 = "SELECT * FROM $tableName LIMIT $start, $limit"; $result = mysql_query($query1); // Initial page num setup if ($page == 0){$page = 1;} $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total_pages/$limit); $LastPagem1 = $lastpage - 1; $paginate = ''; if($lastpage > 1) { $paginate .= "<div class='paginate'>"; // Previous if ($page > 1){ $paginate.= "<a href='$targetpage?page=$prev'>Previous</a>"; }else{ $paginate.= "<span class='disabled'>Previous</span>"; } // Pages if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few? { // Beginning only hide later pages if($page < 1 + ($stages * 2)) { for ($counter = 1; $counter < 4 + ($stages * 2); $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // Middle hide some front and some back elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2)) { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $page - $stages; $counter <= $page + $stages; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // End only hide early pages else { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } } // Next if ($page < $counter - 1){ $paginate.= "<a href='$targetpage?page=$next'>Next</a>"; }else{ $paginate.= "<span class='disabled'>Next</span>"; } $paginate.= "</div>"; } function displayDreams($all = 0) { /* bring in two variables * $db is our database connection * $max_items is the maximum number * of news items we want to display */ global $db, $max_items; /* query for news items */ if ($all == 0) { /* this query will get all news */ $query = "SELECT dream_id,name,dream,tags FROM dream ORDER BY date_entered DESC"; } $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { /* Here we also make sure no * HTML tags, other than the * ones we want are displayed */ $date = $row['date_entered']; $name = htmlentities ($row['name']); $dream = nl2br (strip_tags ($row['dream'], '<a><b><i><u>')); $tags = $row['tags']; /* display the data */ echo "<h1>" . $row['name'] . "</h1>"; echo "<p class='dream'>" . $row['dream'] . "</p>"; echo "<p class='tags'>" . $row['tags'] . "</p>"; echo "<p class='date'>" . $row['date_entered'] . "</p>"; /* get number of comments */ $comment_query = "SELECT count(*) FROM dreams_comments WHERE dream_id={$row['dream_id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); /* display number of comments with link */ echo "<p class='comments'><a href=\"{$_SERVER['PHP_SELF']}?action=show&id={$row['dream_id']}\">Comments ($comment_row[0])</a></p>"; echo "</br>"; } /* if we aren't displaying all dream, * then give a link to do so */ if ($all == 0) { echo "<a href=\"{$_SERVER['PHP_SELF']}\"?action=all'\">'View all dreams'</a>"; } } function displayOneItem($id) { global $db; /* query for item */ $query = "SELECT * FROM `dream` WHERE `dream_id` = '$id'"; $result = mysql_query ($query); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "Bad Dream ID\n"; return; } $row = mysql_fetch_assoc($result); /* easier to read variables and * striping out tags */ $name = htmlentities ($row['name']); $dream = nl2br (strip_tags ($row['dream'], '<a><b><i><u>')); $tags = ($row['tags']); /* display the items */ echo "<h1>" . $row['name'] . "</h1>"; echo "<p class='dream'>" . $row['dream'] . "</p>"; echo "<p class='tags'>" . $row['tags'] . "</p>"; echo "<p class='date'>" . $row['date_entered'] . "</p>"; echo "</br>"; /* now show the comments */ echo "<p class id='comments'>displayComments($id)</p>"; } function displayComments($id) { /* bring db connection variable into scope */ global $db; /* query for comments */ $query = "SELECT * FROM dreams_comments WHERE dream_id=$id"; $result = mysql_query ($query); echo "Comments:</br>"; /* display the all the comments */ while ($row = mysql_fetch_assoc ($result)) { $name = htmlentities ($row['name']); echo "<h2>$name</h2>"; $comment = strip_tags ($row['comment'], '<a><b><i><u>'); $comment = nl2br ($comment); echo "<p class='user_comment'>$comment</p>"; echo "</br>"; } /* add a form where users can enter new comments */ echo "Leave a comment!</br>"; echo "</ br>"; echo "<form id='addcomment' action=\"" . $_SERVER['PHP_SELF'] . "?action=addcomment&id=$id\" method='POST'>"; echo "<table border='0'>"; echo "<tr><td>Name:</td><td><input type'text' width'30' name='name'></td></tr>"; echo "<tr><td>Comment:</td><td><textarea cols='30' rows='10' name='comment'></textarea></td></tr>"; echo "<tr><td><input type='submit' name='submit' value='Add Comment'</td></tr>"; echo "</form>"; echo "</table>"; } function addComment($id) { global $db; /* insert the comment */ $query = "INSERT INTO dreams_comments VALUES('','$id','$_POST[name]','$_POST[comment]')"; mysql_query($query); echo "Comment entered. Thanks!</br>"; echo "<a href=\"{$_SERVER['PHP_SELF']}?action=show&id=$id\">Back</a>"; } /* this is where the script decides what do do */ switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayDreams(1); break; case 'addcomment': addComment($_GET['id']); break; default: displayDreams(); } // pagination echo $paginate; echo $total_pages.' Results'; ?>
  8. Oh wait, I dont know what's happened but it's working now! Cheers for the help mann, means alot to me
  9. My bad, I'm also tired Here we go: <table border='1' width='300'><TR><TD>Sarah</TD></TR><TR><TD>I was watching Heroes and Sylar started to chase me</TD></TR><TR><TD>sylar,heroes</TD></TR></TABLE></br>Comments:</br>Leave a comment!</br></br><form id='addcomment' action="/mydreamz/comments.php?action=addcomment&id=16" method='POST'>Name: <input type'text' width'30' name='name'></br>Comment: <textarea cols='30' rows='10' name='comment'></textarea></br><input type='submit' name='submit' value='Add Comment'</form>
  10. Ok so here's the page source: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Object not found!</title> <link rev="made" href="mailto:postmaster@localhost" /> <style type="text/css"><!--/*--><![CDATA[/*><!--*/ body { color: #000000; background-color: #FFFFFF; } a:link { color: #0000CC; } p, address {margin-left: 3em;} span {font-size: smaller;} /*]]>*/--></style> </head> <body> <h1>Object not found!</h1> <p> The requested URL was not found on this server. The link on the <a href="http://localhost/mydreamz/comments.php%3faction=show&id=19">referring page</a> seems to be wrong or outdated. Please inform the author of <a href="http://localhost/mydreamz/comments.php%3faction=show&id=19">that page</a> about the error. </p> <p> If you think this is a server error, please contact the <a href="mailto:postmaster@localhost">webmaster</a>. </p> <h2>Error 404</h2> <address> <a href="/">localhost</a><br /> <span>23/01/2010 22:43:43<br /> Apache/2.2.12 (Win32) DAV/2 mod_ssl/2.2.12 OpenSSL/0.9.8k mod_autoindex_color PHP/5.3.0 mod_perl/2.0.4 Perl/v5.10.0</span> </address> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.