PDA

View Full Version : Simple email signup database with PHP?


jedifunk
10-15-2003, 01:41 PM
Hey all;

I'm trying to setup a simple email signup database using PHP. But I can't get it to record the email addresses in the .dat file. Any help is really appreciated. Heres what I've got so far.

Ok, the input text field is inside an MC (newsMC) which is on the main stage. One frame 1 of newsMC I have the following AS:
// Create a External Variable Object
newsletter_vars = new LoadVars();
newsletter_request = function () {
var emailvalidate = newsletterEmail.text; // Grab "emailField" text value for validation
if (emailvalidate.indexOf("@") == -1 || emailvalidate.indexOf(".") == -1) { // Parse "emailvalidate" for required email characters "@" and "."
trace("Invalid E-mail"); // Debug Prompt for check parse function correct
yesNo = "Invalid Address";
break; // Kill function
} else { // if "emailvalidate" parse finds "@" and "."
trace("Valid E-mail. Processing Form"); // Debug Prompt
newsletter_vars.submit=true;
newsletter_vars.supplied_email = newsletterEmail.text; // State new Variable for "newsletter_vars"
newsletter_vars.sendAndLoad("newsletter_handle.php", newsletter_vars, "GET"); // Finally, send (and load) "newsletter_vars" variables to Server Side Script
yesNo = "Thanks for joining!";
eNews = "";
}
}

this.joinBtn.onRelease = newsletter_request; // Button Event. Call function on Submission

//Create Return Key Listner
submit_listener = new Object();
submit_listener.onKeyDown = function () {
if (Key.isDown(Key.ENTER)) {
trace ("Enter is depressed");
newsletter_request;
}
}
Key.addListener(submit_listener);
stop();
Now, this is what I have in my PHP script (newsletter_handle.php) on the server:
<?php
function send_reply($vars) {
mail($vars, "TableTurns newsletter request received", "Thank You for subscribing to the TableTurns newsletter. Please do not respond to this email, as it is an auto-response confirmation of your subscription to the newsletter. The newsletter will keep you up to date on all things happening at TableTurns.com, including newly released albums. Once again, we thank you for your support of TableTurns.", "From: dbbt@tableturns.com");
echo "&mailsent=true";
}

function register ($addy) {
// echo "$supplied_email is the email sent";
$newsletter_file = "subscribers.dat";
if (!($fp = fopen($newsletter_file, "r"))) die ("&write_status=failed");
$temp = fread($fp,1000);
fclose($fp);
// Explode/Split Email Address to check address matches
$check = explode("|",$temp);
for($i=0;$i<count($check);$i++) { // Loop through them all
if ($addy == $check[$i]) {
die ("&addres_exist=true"); // if equal kill function... users has already subscribed
}
}
$temp2 = $temp . $addy . "|";
$fp = fopen($newsletter_file, "w");
fwrite ($fp, $temp2);
fclose($fp);
send_reply($addy);
}
switch($submit) {
case "true":
register($supplied_email);
break;
default:
die;
break;
}
?>
Also on the server is a file called subscribers.dat which should hold all the email addresses. But when I copy this to my HD and open it, its a blank document.

Any thoughts on this? Thanks to any and all for help.

butterbur
10-15-2003, 06:23 PM
If register_globals is off in your php.ini file then your variables will only be available as $_GET['variablename']. Only thing I can think to try near my bed time;)
Regards
BB

CyanBlue
10-15-2003, 09:05 PM
Long time no see, butterbur... ;)

Hey, Jedifunk... ;)

First of all... What is the permission of the file, subscribers.dat, set to??? Is it set to 777 ot read/write???

Just out of curiosity, why do you use 'GET' in this line???newsletter_vars.sendAndLoad("newsletter_handle.php", newsletter_vars, "GET");That's all I can think of at the moment... If you still not able to get it working, you might want to post the sample file... Good luck... ;)

freddycodes
10-15-2003, 09:57 PM
Well also


$temp = fread($fp,1000);


Is not going to get enough data probably you need the whole file


$temp = "";
$fp = fopen($newsletter_file, "r") die ("&write_status=failed");
while(!feof($fp))
{
$temp .= fread($fp,1024);
}
fclose($fp);



Also what happens if you use send instead of sendAndLoad to see if anything is erroring on the PHP side of the house.