PHP Warning: fopen() [<a href='function.fopen'>function.fopen</a>]: Filename ca

I haven’t the foggiest, so if you could help:
[php]<?php
$home=getcwd();
function getemail() {
?>

What is your email: <?php return($email); }

function filestart($email,$fileinfo)
{
chdir(“data”);
if(!(file_exists($email))) {
$fptr = fopen($email,“w”) or die(“Unable to open file!1”);
fwrite($fptr," “);
fclose($fptr);
}
$ffptr = fopen($email,“a+”) or die(“Unable to open file!2”);
fwrite($ffptr,$fileinfo);
chdir($home);
}
// $email="[email protected]”;
if (!($_POST[‘Submit’])) {
filestart($email,“The rain in Spain…”);
} else {
getemail();
}

[/php]
it works with the commented line uncommented, but I have no clue as to why it is not working… Help!!!
always,
dg

I changed two parts for you, this should work

[php] <?php
$home=getcwd();
function getemail() {
?>

What is your email: <?php return($email); }

function filestart($email,$fileinfo)
{
chdir(“data”);
if(!(file_exists($email))) {
$fptr = fopen($email,“w”) or die(“Unable to open file!1”);
fwrite($fptr," “);
fclose($fptr);
}
$ffptr = fopen($email,“a+”) or die(“Unable to open file!2”);
fwrite($ffptr,$fileinfo);
chdir($home);
}
// $email="[email protected]”;
$email=$_POST[‘emailaddress’];

if (!($_POST[‘Submit’])) {
filestart($email,“The rain in Spain…”);
} else {
getemail();
}[/php]

Ran it through chrome, and server log reads"
PHP Warning: fopen() [function.fopen]: Filename cannot be empty in /home/gimpware/public_html/test/newfilefuncs.php on line 18

Did you type in an email address?

You don’t have any error handling to prevent submissions with blank email addresses.

It does not get that far with chrome browser… It just says ‘Unable to open file!1’… server log says ‘PHP Warning: fopen() [function.fopen]: Filename cannot be empty in /home/gimpware/public_html/test/newfilefuncs.php on line 18’…

This should work :slight_smile:

[php]<?php
$home=getcwd();
function getemail() {
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>"

method=“post”>
What is your email:
<input type=“text” id=“emailaddress”

name=“emailaddress” maxlength=“50”>
<input type=“submit” name=“Submit”

value=“Submit”>

<?php return($email); } function filestart($email,$fileinfo) { chdir("data"); if(!(file_exists($email))) { $fptr = fopen($email,"w") or die("Unable to open file!1"); fwrite($fptr," "); fclose($fptr); } $ffptr = fopen($email,"a+") or die("Unable to open file!2"); fwrite($ffptr,$fileinfo); chdir($home); } // $email="[email protected]"; $email=$_POST['emailaddress']; if(isset($_POST['Submit'])){ filestart($email,"The rain in Spain..."); } else { getemail(); } ?>[/php]

It works, Top… Thanx…

Sponsor our Newsletter | Privacy Policy | Terms of Service