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:
<html><br/><head><br/> <title>Bob's Auto Parts</title><br/></head><br/><body><br/><h1>Bob's Auto Parts</h1><br/><h2>Order Form</h2><br/><br/><form action="processorder.php" method="post"><br/><table border="0"><br/><tr bgcolor="#cccccc"><br/> <td width="150">Item</td><br/> <td width="15">Quantity</td><br/></tr><br/><tr><br/> <td>Tires</td><br/> <td align="left"><input type="text" name="tireqty" size="3" maxlength="3"/></td><br/></tr><br/><tr><br/> <td>Oil</td><br/> <td align="left"><input type="text" name="oilqty" size="3" maxlength="3"/></td><br/></tr><br/><tr><br/> <td>Spark Plugs</td><br/> <td align="left"><input type="text" name="sparkqty" size="3" maxlength="3"/></td><br/></tr><br/><tr><br/> <td>Shipping Address</td><br/> <td align="center"><input type="text" name="address" size="40" maxlength="40"/></td><br/></tr><br/><tr><br/> <td colspan="2" align="center"><input type="submit" value="Submit Order"/></td><br/></tr><br/></table><br/></form><br/><br/></body><br/></html><br/>
Open the file
The fopen() function can open a file.
$fp = fopen(“$DOCUMENT_ROOT/orders.txt”,’w’);<br/>
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’];<br/>
The document root directory can be obtained in the following 3 ways:
$_SERVER[‘DOCUMENT_ROOT’]$DOCUMENT_ROOT$HTTP_SERVER_VARS[‘DOCUMENT_ROOT’]<br/>
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!