andrew_biggart Posted April 6, 2009 Share Posted April 6, 2009 Ok basically what i am trying to do is for the my profile, manage my blog section of my site i only want users to be able to have a maximum of 3 blog entries at any one time. So i want to use a count command to check if they already have 3 entries and if so echo a message, but if they have less than 3 entries echo the add a new entry form. This is as far as i have got but ive been trying so long i have confused myself so now i need some help please. <?php include("config_contact.php"); $username=$_SESSION['myusername']; // Retrieve data from database $sql = "SELECT count(Blog_username) as blogcount FROM User_blogT WHERE Blog_user='$username' "; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if($row['blogcount'] != 3) { echo "You are only allowed to Have 3 entries to your blog at any one time. If you would like to update your blog please delete one of the older entries."; } else{ echo" <form method='post' action='my_profile_blog_submit.php'> <table class='myprofile_blog'> <tr><td class='myprofile_subtext'>Subject :</td><td class='myprofile_blogsub'> <input name='Blog_subject' type='text' style='width: 413px' /></td></tr> <tr><td class='myprofile_subtext' style='width: 120px' valign='top'>Message :</td><td> <textarea name='Blog_message' style='width: 505px; height: 152px'></textarea></td></tr> </table> <br /> <br /> <br /> <table> <tr><td class='myprofile_changesh'>Add a new entry to your Blog ...</td><td class='myprofile_changesh'> </td></tr> <tr><td class='myprofile_subsub'>Add another entry to your blog. Please delete the older entries that are outdated and try and get it to a limit of 3 or 4 entries.</td></tr> <tr><td colspan='2'></td></tr> </table> <br /> <table class='myprofile_change'> <tr><td><input name='addblog' type='submit' value='Post that shit' /></td></tr> </table> </form> "; } ?> Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted April 6, 2009 Share Posted April 6, 2009 // Retrieve data from database $sql = "SELECT count(Blog_username) as blogcount FROM User_blogT WHERE Blog_user='$username' "; $result = mysql_query($sql); if($result->numRows() > 3) { echo "You are only allowed to Have 3 entries to your blog at any one time. If you would like to update your blog please delete one of the older entries."; } else { } Quote Link to comment Share on other sites More sharing options...
thepip3r Posted April 6, 2009 Share Posted April 6, 2009 did u echo $row['blogcount'] to see if ur getting the results u expect? if you're not, you can either TS that or just run a SELECT SQL query and use mysql_num_rows() to count the number of results... i'd also use if($row['blogcount'] >= 3) { your failure echo statement executes EVERY time unelss the user has submitted 3 entries for that day. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 6, 2009 Author Share Posted April 6, 2009 Ok i have tried this method but its displaying nothing at all. <?php include("config_contact.php"); $username=$_SESSION['myusername']; // Retrieve data from database $sql = "SELECT count(Blog_username) as blogcount FROM User_blogT WHERE Blog_username='$username' "; $result = mysql_query($sql); if($result->numRows() > 3) { echo "You are only allowed to Have 3 entries to your blog at any one time. If you would like to update your blog please delete one of the older entries."; } else{ echo" <form method='post' action='my_profile_blog_submit.php'> <table class='myprofile_blog'> <tr><td class='myprofile_subtext'>Subject :</td><td class='myprofile_blogsub'> <input name='Blog_subject' type='text' style='width: 413px' /></td></tr> <tr><td class='myprofile_subtext' style='width: 120px' valign='top'>Message :</td><td> <textarea name='Blog_message' style='width: 505px; height: 152px'></textarea></td></tr> </table> <br /> <br /> <br /> <table> <tr><td class='myprofile_changesh'>Add a new entry to your Blog ...</td><td class='myprofile_changesh'> </td></tr> <tr><td class='myprofile_subsub'>Add another entry to your blog. Please delete the older entries that are outdated and try and get it to a limit of 3 or 4 entries.</td></tr> <tr><td colspan='2'></td></tr> </table> <br /> <table class='myprofile_change'> <tr><td><input name='addblog' type='submit' value='Post that shit' /></td></tr> </table> </form> "; } ?> and yes i have echo's the blogcount and it is reconsiing the amount of entries i have. Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted April 6, 2009 Share Posted April 6, 2009 I gave a bad example. That example uses pear MDB2 class. You can ignore it. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 6, 2009 Author Share Posted April 6, 2009 Ok ive got it showing up now, but when i added the third entry it still shows up ??? <br /> <?php include("config_contact.php"); $username=$_SESSION['myusername']; // Retrieve data from database $sql = "SELECT count(Blog_username) as blogcount FROM User_blogT WHERE Blog_username='$username' "; $result = mysql_query($sql); if($row['blogcount'] >= 3) { echo "You are only allowed to Have 3 entries to your blog at any one time. If you would like to update your blog please delete one of the older entries."; } else{ echo" <form method='post' action='my_profile_blog_submit.php'> <table class='myprofile_blog'> <tr><td class='myprofile_subtext'>Subject :</td><td class='myprofile_blogsub'> <input name='Blog_subject' type='text' style='width: 413px' /></td></tr> <tr><td class='myprofile_subtext' style='width: 120px' valign='top'>Message :</td><td> <textarea name='Blog_message' style='width: 505px; height: 152px'></textarea></td></tr> </table> <br /> <br /> <br /> <table> <tr><td class='myprofile_changesh'>Add a new entry to your Blog ...</td><td class='myprofile_changesh'> </td></tr> <tr><td class='myprofile_subsub'>Add another entry to your blog. Please delete the older entries that are outdated and try and get it to a limit of 3 or 4 entries.</td></tr> <tr><td colspan='2'></td></tr> </table> <br /> <table class='myprofile_change'> <tr><td><input class='submit_blog' name='addblog' type='submit' value='Post that shit' /></td></tr> </table> </form> "; } ?> Quote Link to comment Share on other sites More sharing options...
thepip3r Posted April 6, 2009 Share Posted April 6, 2009 change >= to > Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 6, 2009 Author Share Posted April 6, 2009 Ive tried that but the form is still showing up! Quote Link to comment Share on other sites More sharing options...
thepip3r Posted April 6, 2009 Share Posted April 6, 2009 well the logic is simple, i don't know what to tell you except change ur code to see what your problem is when the conditional is firing when it's not supposed to be: if($row['blogcount'] >= 3) { echo "rowcount: $row[blogcount] <br>"; echo "You are only allowed to Have 3 entries to your blog at any one time. If you would like to update your blog please delete one of the older entries."; } else{ echo "rowcount: $row[blogcount] <br>"; echo" Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 6, 2009 Author Share Posted April 6, 2009 If i use this code it echo's that there is 3 blog entries for this user. <?php include("config_contact.php"); $username=$_SESSION['myusername']; // Retrieve data from database $sql = "SELECT count(Blog_username) as blogcount FROM User_blogT WHERE Blog_username='$username' "; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if($row['blogcount'] > 0) { echo "(" . $row['blogcount'] . ")"; } ?> But using this code the form just always shows up! can anyone see whats wrong? <?php include("config_contact.php"); $username=$_SESSION['myusername']; // Retrieve data from database $sql = "SELECT count(Blog_username) as blogcount FROM User_blogT WHERE Blog_username='$username' "; $result = mysql_query($sql); if($row['blogcount'] > 3){ echo "You are only allowed to Have 3 entries to your blog at any one time. If you would like to update your blog please delete one of the older entries."; } else{ echo" <form method='post' action='my_profile_blog_submit.php'> <table class='myprofile_blog'> <tr><td class='myprofile_subtext'>Subject :</td><td class='myprofile_blogsub'> <input name='Blog_subject' type='text' style='width: 413px' /></td></tr> <tr><td class='myprofile_subtext' style='width: 120px' valign='top'>Message :</td><td> <textarea name='Blog_message' style='width: 505px; height: 152px'></textarea></td></tr> </table> <br /> <br /> <br /> <table> <tr><td class='myprofile_changesh'>Add a new entry to your Blog ...</td><td class='myprofile_changesh'> </td></tr> <tr><td class='myprofile_subsub'>Add another entry to your blog. Please delete the older entries that are outdated and try and get it to a limit of 3 or 4 entries.</td></tr> <tr><td colspan='2'></td></tr> </table> <br /> <table class='myprofile_change'> <tr><td><input class='submit_blog' name='addblog' type='submit' value='Post that shit' /></td></tr> </table> </form> "; } ?> Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 6, 2009 Author Share Posted April 6, 2009 Anyone? Please! Quote Link to comment Share on other sites More sharing options...
premiso Posted April 6, 2009 Share Posted April 6, 2009 $result = mysql_query($sql); $row = mysql_fetch_assoc($result); You never set $row to the result before you use it in the if statement. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 6, 2009 Author Share Posted April 6, 2009 Im still not to sure what you mean? Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 6, 2009 Author Share Posted April 6, 2009 This is the most recent code i am using btw! <?php include("config_contact.php"); $username=$_SESSION['myusername']; // Retrieve data from database $sql = "SELECT count(Blog_username) as blogcount FROM User_blogT WHERE Blog_username='$username' "; $result = mysql_query($sql); if($row['blogcount'] > 3){ echo "You are only allowed to Have 3 entries to your blog at any one time. If you would like to update your blog please delete one of the older entries."; } else{ echo" <form method='post' action='my_profile_blog_submit.php'> <table class='myprofile_blog'> <tr><td class='myprofile_subtext'>Subject :</td><td class='myprofile_blogsub'> <input name='Blog_subject' type='text' style='width: 413px' /></td></tr> <tr><td class='myprofile_subtext' style='width: 120px' valign='top'>Message :</td><td> <textarea name='Blog_message' style='width: 505px; height: 152px'></textarea></td></tr> </table> <br /> <br /> <br /> <table> <tr><td class='myprofile_changesh'>Add a new entry to your Blog ...</td><td class='myprofile_changesh'> </td></tr> <tr><td class='myprofile_subsub'>Add another entry to your blog. Please delete the older entries that are outdated and try and get it to a limit of 3 or 4 entries.</td></tr> <tr><td colspan='2'></td></tr> </table> <br /> <table class='myprofile_change'> <tr><td><input class='submit_blog' name='addblog' type='submit' value='Post that shit' /></td></tr> </table> </form> "; } ?> Quote Link to comment Share on other sites More sharing options...
premiso Posted April 6, 2009 Share Posted April 6, 2009 <?php include("config_contact.php"); $username=$_SESSION['myusername']; // Retrieve data from database $sql = "SELECT count(Blog_username) as blogcount FROM User_blogT WHERE Blog_username='$username' "; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if($row['blogcount'] > 3){ ... Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 6, 2009 Author Share Posted April 6, 2009 Ok so now its just echoing the blog full status even when i only have 2 entries in my blog!! <?php include("config_contact.php"); $username=$_SESSION['myusername']; // Retrieve data from database $sql = "SELECT count(Blog_username) as blogcount FROM User_blogT WHERE Blog_username='$username' "; $result = mysql_query($sql); if($row['blogcount'] = 3) { echo "You are only allowed to Have 3 entries to your blog at any one time. If you would like to update your blog please delete one of the older entries."; } else{ echo" <form method='post' action='my_profile_blog_submit.php'> <table class='myprofile_blog'> <tr><td class='myprofile_subtext'>Subject :</td><td class='myprofile_blogsub'> <input name='Blog_subject' type='text' style='width: 413px' /></td></tr> <tr><td class='myprofile_subtext' style='width: 120px' valign='top'>Message :</td><td> <textarea name='Blog_message' style='width: 505px; height: 152px'></textarea></td></tr> </table> <br /> <br /> <br /> <table> <tr><td class='myprofile_changesh'>Add a new entry to your Blog ...</td><td class='myprofile_changesh'> </td></tr> <tr><td class='myprofile_subsub'>Add another entry to your blog. Please delete the older entries that are outdated and try and get it to a limit of 3 or 4 entries.</td></tr> <tr><td colspan='2'></td></tr> </table> <br /> <table class='myprofile_change'> <tr><td><input class='submit_blog' name='addblog' type='submit' value='Post that shit' /></td></tr> </table> </form> "; } ?> Quote Link to comment Share on other sites More sharing options...
premiso Posted April 6, 2009 Share Posted April 6, 2009 Each time you post code you revert or change something completely. I do not know where you are getting your logic but it seems as though you keep disregarding any changes made. This is my last attempt to help. <?php include("config_contact.php"); $username=$_SESSION['myusername']; // Retrieve data from database $sql = "SELECT count(Blog_username) as blogcount FROM User_blogT WHERE Blog_username='$username' "; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); // You have to have this for it to even work at all. // if($row['blogcount'] = 3) { // Single equals always amounts to true: if ($row['blogcount'] == 3) { // the double euqal is the comparison and should be used instead. echo "You are only allowed to Have 3 entries to your blog at any one time. If you would like to update your blog please delete one of the older entries."; } else{ echo" <form method='post' action='my_profile_blog_submit.php'> <table class='myprofile_blog'> <tr><td class='myprofile_subtext'>Subject :</td><td class='myprofile_blogsub'> <input name='Blog_subject' type='text' style='width: 413px' /></td></tr> <tr><td class='myprofile_subtext' style='width: 120px' valign='top'>Message :</td><td> <textarea name='Blog_message' style='width: 505px; height: 152px'></textarea></td></tr> </table> <br /> <br /> <br /> <table> <tr><td class='myprofile_changesh'>Add a new entry to your Blog ...</td><td class='myprofile_changesh'> </td></tr> <tr><td class='myprofile_subsub'>Add another entry to your blog. Please delete the older entries that are outdated and try and get it to a limit of 3 or 4 entries.</td></tr> <tr><td colspan='2'></td></tr> </table> <br /> <table class='myprofile_change'> <tr><td><input class='submit_blog' name='addblog' type='submit' value='Post that shit' /></td></tr> </table> </form> "; } ?> Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 6, 2009 Author Share Posted April 6, 2009 Ok ive got my head around it now and it is working with that code! thankyou very much premiso! Quote Link to comment 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.