ecabrera Posted August 12, 2011 Share Posted August 12, 2011 help with this plz when i i got to a profile i cant see the comment it shows like this Notice: Undefined index: comment in /home/ecabrera/public_html/profile.php on line 179 $comment = nl2br ($row['comment']); and when i add a comment i get this Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ecabrera/public_html/profile.php on line 128 $numerows = mysql_num_rows($query); Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/ Share on other sites More sharing options...
AyKay47 Posted August 12, 2011 Share Posted August 12, 2011 these are basic errors, however it will be much easier to correct these if we can see your code.. Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256341 Share on other sites More sharing options...
Maq Posted August 12, 2011 Share Posted August 12, 2011 help with this please We got that from your title. Undefined index: Post more of the relevant code. Are you selecting this from a DB? If not, how is this array being generated? supplied argument is not a valid MySQL result Usually caused by an invalid query. Again, post more relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256342 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 // comment button action if (@$_POST['commentbtn']){ if ($username){ $comment = $_POST['comment']; if ($comment){ if ($userid != $getid){ $query = mysql_query("SELECT * FROM profile_comments WHERE profile_id='$getid' AND user_id='$userid' AND comment='$comment'"); $numerows = mysql_num_rows($query); if ($numrows != 0){ $commdate = date("F d, Y"); // October 08, 2010 mysql_query("INSERT INTO profile_comments VALUES ('', '$getid', '$userid', '$username', '$comment', '$commdate')"); // email profile owner $webmaster = "admin@maliferulez.com"; $headers = "From: Ma Life Rulez<$webmaster>"; $subject = "$username has commented on your profile"; $message = "Hello $firstname $lastname. $username has posted a comment on your profile on Maliferulez.com"; $message .= " The message $username has posted with is below.\n"; $message .= "\n****************************************************************\n"; $message .= "$comment"; $message .= "\n\n****************************************************************\n\n"; $message .= "Click here to view $username's profile $site/profile?id=$userid\n"; $message .= "Click here to view your profile $site/profile?id=$getid\n"; // send email mail($email, $subject, $message, $headers); $msg = "Your comment has been added and is shown above."; } else $msg = "You can not submit the same comment twice."; } else $msg = "You can not comment on your own profile."; } else $msg = "You did not supply a comment."; } else $msg = "You must be logged in to comment on profiles."; } // display comments $perpage = 10; $start=0; if(@$_GET['s']) $start = $_GET['s']; $query = mysql_query("SELECT * FROM profile_comments WHERE profile_id='$getid' ORDER BY id DESC LIMIT $start, $perpage"); $numrows = mysql_num_rows($query); if ($numrows > 0){ $next = $start + $perpage; $prev = $start - $perpage; while($row = mysql_fetch_assoc($query)){ $user_id = $row['user_id']; $user_name = $row['user_name']; $comment = nl2br ($row['comment']); $date = $row['date']; echo "<b>Posted by <a href='$site/profile?id=$user_id'>$user_name</a> on $date</b><br />"; echo "<div style='margin-left: 10px;'>$comment</div><hr>"; } } else echo "This user has no profile comments.<br />"; // end diplay comment area // show comment nav echo "<div style='float: right;'>"; if (!($start <= 0)) echo "<a href='$site/profile?id=$getid&s=$prev#comments'>Previous</a>"; if (!($start > $numrows - $perpage)) echo "<a href='$site/profile?id=$getid&s=$next#comments'>Next</a>"; echo "</div>"; if ($username){ // display comment form echo "<a name='comment-form'></a>"; if ($msg) echo "<b>$msg</b><br />"; echo "<form action='$site/profile?id=$getid#comment-form' method='post'> <table> <tr> <td><textarea name='comment' style='width: 400px; height: 75px;'></textarea></td> </tr> <tr> <td><input type='submit' name='commentbtn' value='Comment'></td> </tr> </table> </form>"; } // end comment box echo "</div></div> <b class='corners'> <b class='corners5'></b> <b class='corners4'></b> <b class='corners3'></b> <b class='corners2'><b></b></b> <b class='corners1'><b></b></b></b> </div>"; Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256344 Share on other sites More sharing options...
AyKay47 Posted August 12, 2011 Share Posted August 12, 2011 1. instead of if($comment), use if(!empty($comment)) 2.do the same for $userid and $getid 3. this should also fix your query issue.. Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256349 Share on other sites More sharing options...
JasonLewis Posted August 12, 2011 Share Posted August 12, 2011 I'd like to point out that suppressing errors with @ for $_POST['commentbtn'] isn't a good approach. Instead, use isset if(isset($_POST['commentbtn'])) Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256351 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 if i put this if(!empty($comment)){ if (!empty($userid) != !empty($getid){ and when i refresh i get a server error Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256352 Share on other sites More sharing options...
AyKay47 Posted August 12, 2011 Share Posted August 12, 2011 if (!empty($userid) && !empty($getid) && ($userid != $getid)){ Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256361 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 nope still doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256363 Share on other sites More sharing options...
AyKay47 Posted August 12, 2011 Share Posted August 12, 2011 the code I posted will not cause a server error.. check you error.log for errors.. Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256368 Share on other sites More sharing options...
AyKay47 Posted August 12, 2011 Share Posted August 12, 2011 also, I would change those two lines to this anyway.. if(!empty($comment) && !empty($userid) && !empty(getid)){ if ($userid != $getid){ Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256369 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 nope and i did tryed it but i took your code of when it didnt work <?php $getid=""; if(@$_GET['id']) $getid = $_GET['id']; if ($getid){ require('scripts/connect.php'); $query = mysql_query("SELECT * FROM users WHERE id='$getid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $user = $row['username']; $bio = $row['bio']; $youtube = $row['youtube']; $title = "$user's Profile on Maliferulez"; $meta_description = "$bio"; $meta_keywords = "$youtube"; } else $title = "Opps!!! Profile not found!"; mysql_close(); } else $title = "Profiles"; ?> <?php require("styles/top.php"); ?> <div id='full'> <?php $msg=""; if (!$getid) $getid = "1"; require('scripts/connect.php'); $query = mysql_query("SELECT * FROM users WHERE id='$getid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $id = $row['id']; $firstname = $row['first_name']; $lastname = $row['last_name']; $user = $row['username']; $email = $row['email']; $avatar = $row['avatar']; $bio = nl2br($row['bio']); $youtube = $row['youtube']; $lastlogin = $row['last_login']; $active = $row['active']; $locked = $row['locked']; $date = $row['date']; if ($locked == 0){ echo "<div id='profile'> <div id='leftside'> <img src='avatars/$avatar' width='250px' height='250px' style='border: 3px double #000;'></img> </div> <div id='rightside'> <div> <b class='corners'> <b class='corners1'><b></b></b> <b class='corners2'><b></b></b> <b class='corners3'></b> <b class='corners4'></b> <b class='corners5'></b></b> <div class='cornersfg'> <div class='top'>$user's Profile</div> </div> <div class='bottom'> <b>Joined</b> - $date<br /> <b>Last Login</b> - $lastlogin<br />"; if ($youtube) echo "<br /><b><u>Youtube Channel:</u></b><br /> <a href='http://www.youtube.com/$youtube'>$youtube</a><br />"; if ($bio) echo "<br/>$bio"; echo "</div> <b class='corners'> <b class='corners5'></b> <b class='corners4'></b> <b class='corners3'></b> <b class='corners2'><b></b></b> <b class='corners1'><b></b></b></b> </div>"; /* if ($youtube) echo "<script src='http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/youtube.xml&up_channel=$youtube&synd=open&w=275&h=390&title=&border=%23ffffff%7C3px%2C1px+solid+%23999999&output=js'></script>"; */ echo "<a name='comments'></a><div style='margin-top: 15px;'> <b class='corners'> <b class='corners1'><b></b></b> <b class='corners2'><b></b></b> <b class='corners3'></b> <b class='corners4'></b> <b class='corners5'></b></b> <div class='cornersfg'> <div class='top'>$user's Profile Comments</div> </div> <div class='bottom'>"; // comment button action if (@$_POST['commentbtn']){ if ($username){ $comment = $_POST['comment']; if(!empty($comment)){ if (!empty($userid) != $getid){ $query = mysql_query("SELECT * FROM profile_comments WHERE profile_id='$getid' AND user_id='$userid' AND comment='$comment'"); $numerows = mysql_num_rows($query); if ($numrows != 0){ $commdate = date("F d, Y"); // October 08, 2010 mysql_query("INSERT INTO profile_comments VALUES ('', '$getid', '$userid', '$username', '$comment', '$commdate')"); // email profile owner $webmaster = "admin@maliferulez.com"; $headers = "From: Ma Life Rulez<$webmaster>"; $subject = "$username has commented on your profile"; $message = "Hello $firstname $lastname. $username has posted a comment on your profile on Maliferulez.com"; $message .= " The message $username has posted with is below.\n"; $message .= "\n****************************************************************\n"; $message .= "$comment"; $message .= "\n\n****************************************************************\n\n"; $message .= "Click here to view $username's profile $site/profile?id=$userid\n"; $message .= "Click here to view your profile $site/profile?id=$getid\n"; // send email mail($email, $subject, $message, $headers); $msg = "Your comment has been added and is shown above."; } else $msg = "You can not submit the same comment twice."; } else $msg = "You can not comment on your own profile."; } else $msg = "You did not supply a comment."; } else $msg = "You must be logged in to comment on profiles."; } // display comments $perpage = 10; $start=0; if(@$_GET['s']) $start = $_GET['s']; $query = mysql_query("SELECT * FROM profile_comments WHERE profile_id='$getid' ORDER BY id DESC LIMIT $start, $perpage"); $numrows = mysql_num_rows($query); if ($numrows > 0){ $next = $start + $perpage; $prev = $start - $perpage; while($row = mysql_fetch_assoc($query)){ $user_id = $row['user_id']; $user_name = $row['user_name']; $comment = nl2br ($row['comment']); $date = $row['date']; echo "<b>Posted by <a href='$site/profile?id=$user_id'>$user_name</a> on $date</b><br />"; echo "<div style='margin-left: 10px;'>$comment</div><hr>"; } } else echo "This user has no profile comments.<br />"; // end diplay comment area // show comment nav echo "<div style='float: right;'>"; if (!($start <= 0)) echo "<a href='$site/profile?id=$getid&s=$prev#comments'>Previous</a>"; if (!($start > $numrows - $perpage)) echo "<a href='$site/profile?id=$getid&s=$next#comments'>Next</a>"; echo "</div>"; if ($username){ // display comment form echo "<a name='comment-form'></a>"; if ($msg) echo "<b>$msg</b><br />"; echo "<form action='$site/profile?id=$getid#comment-form' method='post'> <table> <tr> <td><textarea name='comment' style='width: 400px; height: 75px;'></textarea></td> </tr> <tr> <td><input type='submit' name='commentbtn' value='Comment'></td> </tr> </table> </form>"; } // end comment box echo "</div></div> <b class='corners'> <b class='corners5'></b> <b class='corners4'></b> <b class='corners3'></b> <b class='corners2'><b></b></b> <b class='corners1'><b></b></b></b> </div>"; // end right column echo "</div>"; } else echo "<font color='red'><center><h1>The profile you have selected is currently locked.</h1></center></font>"; } else echo "No user was found."; ?> </div> <div id='left'> </div> <div id='right'> </div> <?php require("styles/bottom.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/244601-help/#findComment-1256373 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.