Data or information we usually store into a database or use microsoft office, but this time different from the usual we save the file using extension html, txt, php and so forth.
This step is very easy and not too complicated for you to follow because only a few steps we will be able to see the results we do, if you are curious below there are some explanations how to make it
<h2>> Menyimpan Data dengan cara Menggunakan PHP </h2>
<table>
<form method="post" action="">>
;tr><td>Nama</td><td><input type="></td></tr>
<tr><td>Isi</td><td><text" name="nama" style="width:300px"></td></tr>
<tr><td>Isi</td><td><textarea name="data" style="width:300px"><t;</textarea></td></tr>
<tr><td></td><td><input type="submit" name="ok" value="Simpan"></td></tr>
</form>
</table>
<?php
if(isset($_POST['ok'])){
if(empty($_POST['nama']) || empty($_POST['data'])){
print "Lengkapi form";
}else{
$nama=$_POST['nama'];
$data=$_POST['data'];
$tanggal=date("h:i:s");
$buka=fopen("hasil.html",'a');
fwrite($buka,"nama : ${nama} <br> ");
fwrite($buka,"dibuat : ${tanggal} <br> ");
fwrite($buka," isi : ${data} <br> ");
fwrite($buka,"<hr>");
fclose($buka);
print "data berhasil disimpan";
}
fopen() function opens the file Then follows the mode parameter "a" , this mode parameter opens the file and puts the pointer at the end of the file, if the file does not exist then it will be created first.
so the file "hasil.html"if nothing will be created first, and if it exists then the data will be added after the previous data.
there are many fopen () mode options, as shown in the following table.
| mode | Description |
|---|---|
| 'r' | Open for reading only; place the file pointer at the beginning of the file. |
| 'r+' | Open for reading and writing; place the file pointer at the beginning of the file. |
| 'w' | Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. |
| 'w+' | Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. |
| 'a' | Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. In this mode, fseek() has no effect, writes are always appended. |
| 'a+' | Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. In this mode, fseek() only affects the reading position, writes are always appended. |
| 'x' | Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL_O_CREAT flags for the underlying open(2) system call. |
| 'x+' | Create and open for reading and writing; otherwise it has the same behavior as 'x'. |
| 'c' | Open the file for writing only. If the file does not exist, it is created. If it exists, it is neither truncated (as opposed to 'w'), nor the call to this function fails (as is the case with 'x'). The file pointer is positioned on the beginning of the file. This may be useful if it's desired to get an advisory lock (see flock()) before attempting to modify the file, as using 'w' could truncate the file before the lock was obtained (if truncation is desired, ftruncate() can be used after the lock is requested). |
| 'c+' | Open the file for reading and writing; otherwise it has the same behavior as 'c'. |
| e' | Set close-on-exec flag on the opened file descriptor. Only available in PHP compiled on POSIX.1-2008 conform systems. |
Then fwrite () works to write something into the file.
Then close () works to close the file again.
Please try and see the results by opening the file "database.html "