Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder seanmarkham's Avatar
    Join Date
    Dec 2011
    Location
    Lincolnshire, England
    Posts
    50
    Thanks
    11
    Thanked 0 Times in 0 Posts

    fwrite entry limit.

    Been trying to find a method that allows me to only permit 20 entries using the fwrite formula, can a check be done to see if a file has a certain amount of lines? then if the required amount of lines has been met then an error message is displayed.

    This is my current code, that works as it is.

    PHP Code:
    <?php
    $to 
    "info@mymail.co.uk";
    $username $_REQUEST['username1'];
    $string "$username<br />\n\n";
    $headers "From: entry form";

    $date1"2013-05-05";
    $round1_date strtotime ($date1);

    $date2 "2013-02-06";
    $round2_date strtotime ($date2);
    $date3 "2013-07-07";
    $round3_date strtotime ($date3);
    $date4 "2013-04-08";
    $round4_date strtotime ($date4);
    $date5"2013-01-09";
    $round5_date strtotime ($date5);
    $date6 "2013-13-10";
    $round6_date strtotime ($date6);
    $date7 "2013-10-11";
    $round7_date strtotime ($date7);

    $round1 "entry - Round 1 - Group 1";
    $round2 "entry - Round 2 - Group 1";
    $round3 "entry - Round 3 - Group 1";
    $round4 "entry - Round 4 - Group 1";
    $round5 "entry - Round 5 - Group 1";
    $round6 "entry - Round 6 - Group 1";
    $round7 "entry - Round 7 - Group 1";

    $file1 "round1/group1.txt";
    $file2 "round2/group1.txt";
    $file3 "round3/group1.txt";
    $file4 "round4/group1.txt";
    $file5 "round5/group1.txt";
    $file6 "round6/group1.txt";
    $file7 "round7/group1.txt";


    if (
    $round1_date time() ) { $subject $round1; }
    elseif (
    $round2_date time() ) {$subject $round2; }
    elseif (
    $round3_date time() ) {$subject $round3; }
    elseif (
    $round4_date time() ) {$subject $round4; }
    elseif (
    $round5_date time() ) {$subject $round5; }
    elseif (
    $round6_date time() ) {$subject $round6; }
    else {
    $subject $round7; }



    if (
    $round1_date time() ) { $filename $file1; }
    elseif (
    $round2_date time() ) {$filename $file2; }
    elseif (
    $round3_date time() ) {$filename $file3; }
    elseif (
    $round4_date time() ) {$filename $file4; }
    elseif (
    $round5_date time() ) {$filename $file5; }
    elseif (
    $round6_date time() ) {$filename $file6; }
    else {
    $filename $file7; }



    $body "We have recieved an Entry for group 1:\n\n";
    $body .= $username;

    if(
    $username == '') {print "You have not entered your name, please go back and try again";}

    if(
    $username == 'Full Name') {print "You have not entered your name, please go back and try again";}


    $fp fopen($filename"a");
    fwrite($fp$string);
    fclose($fp);


    if(
    fclose) {mail($to$subject$body$headers);}

    if(
    fclose)
    {
    header"Location: http://www.mysite.co.uk" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@mysite.co.uk";}

    ?>
    Thanks

    Sean

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Rough idea...

    PHP Code:
    $lines file('some_file_name'); /* read file into an array */
    if(count($lines)>19) {
     
    /* file has 20 lines so do whatever */
    }else{
     
    /* file has less than 20 lines, so do something else */


  • Users who have thanked litebearer for this post:

    seanmarkham (05-09-2013)

  • #3
    New Coder seanmarkham's Avatar
    Join Date
    Dec 2011
    Location
    Lincolnshire, England
    Posts
    50
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Worked perfectly, I needed to double the amount of lines as the function uses two, I have copied the working script below.

    PHP Code:
    <?php 
    $to 
    "info@mymail.co.uk"
    $username $_REQUEST['username1']; 
    $string "$username<br />\n\n"
    $headers "From: entry form"

    /* yyyy-mm-dd */
    $date1"2013-05-05";
    $round1_date strtotime ($date1);
    $date2 "2013-06-02";
    $round2_date strtotime ($date2);
    $date3 "2013-07-07";
    $round3_date strtotime ($date3);
    $date4 "2013-08-04";
    $round4_date strtotime ($date4);
    $date5"2013-09-01";
    $round5_date strtotime ($date5);
    $date6 "2013-10-13";
    $round6_date strtotime ($date6);
    $date7 "2013-11-10";
    $round7_date strtotime ($date7);

    $round1 "entry - Round 1 - Group 1"
    $round2 "entry - Round 2 - Group 1"
    $round3 "entry - Round 3 - Group 1"
    $round4 "entry - Round 4 - Group 1"
    $round5 "entry - Round 5 - Group 1"
    $round6 "entry - Round 6 - Group 1"
    $round7 "entry - Round 7 - Group 1"

    $file1 "round1/group1.txt"
    $file2 "round2/group1.txt"
    $file3 "round3/group1.txt"
    $file4 "round4/group1.txt"
    $file5 "round5/group1.txt"
    $file6 "round6/group1.txt"
    $file7 "round7/group1.txt"


    if (
    $round1_date time() ) { $subject $round1; } 
    elseif (
    $round2_date time() ) {$subject $round2; } 
    elseif (
    $round3_date time() ) {$subject $round3; } 
    elseif (
    $round4_date time() ) {$subject $round4; } 
    elseif (
    $round5_date time() ) {$subject $round5; } 
    elseif (
    $round6_date time() ) {$subject $round6; } 
    else {
    $subject $round7; } 



    if (
    $round1_date time() ) { $filename $file1; } 
    elseif (
    $round2_date time() ) {$filename $file2; } 
    elseif (
    $round3_date time() ) {$filename $file3; } 
    elseif (
    $round4_date time() ) {$filename $file4; } 
    elseif (
    $round5_date time() ) {$filename $file5; } 
    elseif (
    $round6_date time() ) {$filename $file6; } 
    else {
    $filename $file7; } 

    $lines file($filename); /* read file into an array */ 
    if(count($lines)>39) { header"Location: http://www.ancasterkarting.co.uk/secure/entry-full.php" );
    }else{ 
     
    /* file has less than 40 lines, so do something else */ 


    $body "We have recieved an Entry for group 1:\n\n"
    $body .= $username

    if(
    $username == '') {print "You have not entered your name, please go back and try again";} 

    if(
    $username == 'Full Name') {print "You have not entered your name, please go back and try again";} 


    $fp fopen($filename"a"); 
    fwrite($fp$string); 
    fclose($fp); 


    if(
    fclose) {mail($to$subject$body$headers);} 

    if(
    fclose
    {
    header"Location: http://www.mysite.co.uk" );} 
    else 
    {print 
    "We encountered an error sending your mail, please notify info@mysite.co.uk";} 
    }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •