Web Analytics Made Easy -
StatCounter Disabling an entry more then 3 times a day. - CodingForum

Announcement

Collapse
No announcement yet.

Disabling an entry more then 3 times a day.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Disabling an entry more then 3 times a day.

    Is that possible?
    Like if you enter 3 times a day the same text. It echo's something instead of writing in the database. Do i need to add a date on where the line was added to it?
    I need this because i want to make sure that noone can attack somebody more then 3 times a day on my site: www.gangster-life.tk
    Please Help me

  • #2
    Not sure I see your problem.
    From your brief description, I would think that you need a table with the id of the poster and the id of the attacked + a datetime-field where you insert the current date in. Before making new inserts to this table, you need to run a select and see if there are already of these records. Like
    Select count(*) as numattacks from table where posterID=yourposter and attackedID=theattacked and createdate=Now()
    If numattacks >= 2, then you don’t insert a new row.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      thanks, but can you tell me how i can get the current date in PHP?
      Cheers MPCODER

      Comment


      • #4
        in PHP, the date needs to be composed.
        PHP only has the number of seconds since the unix-epoch, sowhen you need a real date, you need to compose it with date() and then specify in which format you want it. Check out
        http://www.php.net/date to see how you can format it.

        But inside the sql-statement, you can uses Now() to get the date or datetime (depending on the column you insert or match against) like in the statement from my previous post
        Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

        Comment


        • #5
          Thanks!

          Thanks, i got almost everything to work, but now i need it to fill in the real date, now it fills in Now(), i know what i'm doing wrong, just not how i need to do it, here's my code:
          PHP Code:
          <?php 
          error_reporting
          (E_ALL);
          session_start();

          include(
          "config.php");
             
          $attacker $_SESSION['user_name'];
             
          $defender $_POST['defender'];
                if (
          $attacker && $defender) { 
                   
          /* Maak connectie */ 
                   
          $db mysql_connect("localhost""user""pass");
                   
          mysql_select_db("dbl"); 
                   
                   
          $powersql "SELECT won FROM attacks WHERE won='YES' AND user_name='$attacker'";
                   
          $powerresult mysql_query($powersql) or die(mysql_error()); 
                   
          $attackerpower mysql_num_rows($powerresult);
                   
                   
          $powersql2 "SELECT won FROM attacks WHERE won='YES' AND user_name='$defender'";
                   
          $powerresult2 mysql_query($powersql2) or die(mysql_error());
                   
          $defenderpower mysql_num_rows($powerresult2);
                   
                   
          $image 'YES';
                    if (
          $attackerpower >= $defenderpower){
                    
          $image 'YES';
                    }
                    if (
          $defenderpower $attackerpower){
                    
          $image 'NO';
                   }
                   
                   
          $attacktimessql "SELECT * FROM attacks WHERE user_name='$attacker' AND defender='$defender' AND date='Now()'";
                   
          $attacktimesresult mysql_query($attacktimessql) or die(mysql_error());
                   
          $timesattacking mysql_num_rows($attacktimesresult);
                   
                   if (
          $timesattacking >= 2){
                   echo(
          "You can't attack a user more then three times a day");
                   }
                   else {
                    
                   
          /* Maak SQL-query */ 
                   
          $sql "INSERT INTO attacks (won, user_name, defender, date) 
                      VALUES ('
          $image', '$attacker', '$defender', 'Now()')"
                   
          mysql_query($sql); 
                    echo (
          "You, $attacker have just attacked $defender!<br><br>$defender shoots for $defenderpower damage!<br><br>$attacker shoots for $attackerpower damage!<br><br><br><br><br><br><br><br><br>Have you wonned the attack: $image ! <a href='javascript:history.back()'>Go back</a>"); 
                   }
                   exit; 
                } 
          ?>

          Comment


          • #6
            $sql = "INSERT INTO attacks (won, user_name, defender, date)
            VALUES ('$image', '$attacker', '$defender', 'Now()')";

            should be

            $sql = "INSERT INTO attacks (won, user_name, defender, date)
            VALUES ('$image', '$attacker', '$defender', Now())";

            so without the quotes. If it is enclosed in quotes, then it is taken literal.
            If you use it without the quotes, then the current date or datetime is inserted (depending on the columntype)

            But the fact that 'Now()' inserts 'Now()' must mean that the date-column isn't a datetime column, so you need to change the columntype.
            Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

            Comment


            • #7
              Thanks!

              Thanks Raf, but it inserts the seconds now too.
              I tried this:
              $sql = "INSERT INTO attacks (won, user_name, defender, date)
              VALUES ('$image', '$attacker', '$defender', Now(' d-m-Y '))";

              but it still inserts the seconds also, can anyone help me with this please?
              Cheers MPCODER

              Comment


              • #8
                You have probably created a datetime column. If you only want the date (that is yyyy-mm-dd) then you need to set the column as 'date'.
                Now() will then only insert the date-portion.

                You can not specify the format of date or datetime columns. And you shouldn't bother either, since you can specify them when you select the values.
                Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

                Comment

                Working...
                X