ggrant3 Posted April 27, 2008 Share Posted April 27, 2008 I would like to have a function that takes the customers email address from a certain field, check to make sure the email does not already exist, and if it does not then store the email address into a file. But I am still new to php and I am not sure if what I have so far is correct or even what else needs to be added. Also where in the script should I place this code (it is part of a form)? <?php // Define filename and open in read-write append mode $filename = 'C:/private/customeremail.txt'; $file = fopen($filename, 'a+'); // If filesize is zero, no names yet registered // So just write the customer email to file if (filesize($filename) === 0) { fwrite($file, "$email"); } // If filesize is greater than zero, check customer email first else { // Move the internal pointer to the beginning of file rewind($file); // Loop through file one line at a time while (!feof($file)) { $line = fgets($file); // Split line at comma, and check first element against customer email $tmp = explode(', ', $line); // close the file fclose($file); } } That is all I have been able to come up with so far. Link to comment https://forums.phpfreaks.com/topic/103104-help-with-php-function/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.