php - Saving Form Information to File on server -



php - Saving Form Information to File on server -

i need save form input text file on server. have created text file on server "email.txt", , given permissions of 777. when form submitted text file remains blank.

my html follows:

<form action="process.php" method="post"> <input id="email-input" type="text" name="your-email" placeholder="you@yourmail.com" class="cform-text" size="65" title="your email"> <input id="optin-button" type="submit" value="download report" class="cform-submit"> </form>

php follows:

<?php $email = $_post["email-input"]; $to = "you@youremail.com"; $subject = "new email address mailing list"; $headers = "from: $email\n"; $message = "a visitor site has sent next email address added mailing list.\n email address: $email"; $user = "$email"; $usersubject = "thank you"; $userheaders = "from: you@youremailaddress.com\n"; $usermessage = "thank subscribing our mailing list."; mail($to,$subject,$message,$headers); mail($user,$usersubject,$usermessage,$userheaders); $fh = fopen("email.txt", "a"); fwrite($fh, $email); fclose($fh); header("location: mysite.com"); ?>

please assist. give thanks you

your (email) input bears id of id="email-input" yet "named" name="your-email" no match post variable.

change:

$email = $_post["email-input"];

to:

$email = $_post["your-email"];

you cannot rely on id name of element , why file blank.

having used error reporting have signaled error.

n.b.:

i suggest alter fwrite($fh, $email); fwrite($fh, $email . "\n");, otherwise, you're going have accumulated email addresses on 1 continuous line.

add error reporting top of file(s) help find errors.

error_reporting(e_all); ini_set('display_errors', 1);

sidenote: error reporting should done in staging, , never production.

php forms

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -