简体   繁体   中英

How to save a file using PHP?

I'm currently making subscribe form, I got the HTML ready but I got problems in the PHP:

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
?>

Now I got them using php, how can I save them.

I need like to save them anywhere so I can like check them anytime.

like I would open a .txt where it saves and then I find the list of emails and names and messages.

I agree with @prakhar19, a database is better suited to store this kind of info. But if you really want to store this information in a file on the server (because you don't want to setup a database server just for this), go for file_put_contents :

file_put_contents('subscribers.txt',
    $_POST['name'] . '\n' . $_POST['email'] . '\n' . $_POST['message'],
    FILE_APPEND);

You need to make a database for saving the info. Google for ' Databases ' and ' MySql '.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM