Home>Article>Backend Development> How to store data in php
How to store data in php (recommended learning:PHP video tutorial)
There are two basic ways to store data: save to Ordinary file, or save to database. When you have a large number of orders, a database management system should be used.
The Html code is as follows:
Bob's Auto Parts
Bob's Auto Parts
Order Form
Open the file
The fopen() function can open a file.
$fp = fopen(“$DOCUMENT_ROOT/orders.txt”,’w’);
Since we defined a short name for the form variable, we need to add the following code at the beginning of the script:
$DOCUMENT_ROOT = $_SERVER[‘DOCUMENT_ROOT’];
The document root directory can be obtained in the following 3 ways:
$_SERVER[‘DOCUMENT_ROOT’]$DOCUMENT_ROOT$HTTP_SERVER_VARS[‘DOCUMENT_ROOT’]
fopen() has four parameters, the first parameter is the path.
The second parameter is the file mode.
The third parameter is optional, you can use it if you want to search for a file in include_path.
The fourth parameter is also optional. The fopen() function allows the file name to start with the protocol name and open the file in a remote location.
You can also use the fopen() function to open files through FTP, HTTP, or other protocols.
Note that the domain name in the URL is not case-sensitive, but the path and file name may be case-sensitive.
The above is the detailed content of How to store data in php. For more information, please follow other related articles on the PHP Chinese website!