tgavin Posted October 24, 2008 Share Posted October 24, 2008 I'm not getting the proper count. If I enter 3 email address in the form and click submit, the count is 3. Then, I fill out the form with one address and now the total count is 5 instead of 4. I'm sure it's because I'm setting $i=1, but if I don't, then a single address isn't counted. // update counter page function write_file($filename,$content) { // let's make sure the file exists and is writable first. if(is_writable($filename)) { // open the file in write mode so that we erase previous contents if(!$handle = fopen($filename, 'w')) { die("cannot open file: {$filename}"); } // write $status to our opened file. if(fwrite($handle, $content) === FALSE) { die("cannot write to file: {$filename}"); } // close the file fclose($handle); chmod($filename, 0644); } else { die('Could not write to the file located at: '.$filename); } } $emails = trim($_POST['email']); $email = explode(',' , $emails); $previous_count = file_get_contents('count.txt'); $i=1; foreach($email as $to) { $sent = mail($to,$subject,$message,$headers); $i++; } $new_count = $previous_count + $i; write_file('count.txt',$new_count); Link to comment https://forums.phpfreaks.com/topic/129971-solved-net-getting-correct-count/ Share on other sites More sharing options...
kenrbnsn Posted October 24, 2008 Share Posted October 24, 2008 Change: <?php $new_count = $previous_count + $i; ?> to <?php $new_count = $previous_count + count($email); ?> and remove the $i counter. Ken Link to comment https://forums.phpfreaks.com/topic/129971-solved-net-getting-correct-count/#findComment-673793 Share on other sites More sharing options...
tgavin Posted October 24, 2008 Author Share Posted October 24, 2008 Thanks, but that doesn't work either. I posted 3 email addresses and var_dump(count($email)) = 2. Link to comment https://forums.phpfreaks.com/topic/129971-solved-net-getting-correct-count/#findComment-673887 Share on other sites More sharing options...
tgavin Posted October 24, 2008 Author Share Posted October 24, 2008 Let me retract that. I had a period instead of a comma between the first and second email It's working perfectly. Thanks! Link to comment https://forums.phpfreaks.com/topic/129971-solved-net-getting-correct-count/#findComment-673889 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.