Jump to content

Recommended Posts

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>

   ";
   }
?>

// 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

{

 

}

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.

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.

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>

   ";
   }
?>

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"

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>

   ";
   }
?>

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>

   ";
   }
?>

   <?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){  

 

...

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>

   ";
   }

?>

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>

      ";
      }
   
   ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.