Pagine

mercoledì 8 giugno 2011

Apertura di un file

Parte in HTML
<html>
<head>
<title> Scrittura dati anagrafici </title>
</head>
<body>
<center><h2>Gestione dati angrafici </h2>
<form action="scrivi_2.php" method='POST'>
<table border="2">
<tr>
<td> Cognome e nome</td>
<td>Indirizzo</td>
</tr>
<tr>
<td><input name="cognom" maxlegth="30" size="30"></td>
<td><input name="indiri" maxlegth="50" size="50"></td>
</tr>
<tr>
<td>Professione</td>
<td>Data di Nascita</td>
</tr>
<tr>
<td><input name="profes" maxlegth="30" size="30"></td>
<td><input name="datnas" maxlegth="10" size="10"></td>
</tr>
<tr>
<td>Località </td>
<td>e-mail</td>
</tr>
<tr>
<td><input name="locali" maxlegth="30" size="30"></td>
<td><input name="email" maxlegth="50" size="50"></td>
</tr>
<tr>
<td><input type="submit" value="Invia"></td>
<td><input type="reset" value="Cancella"></td>
</tr>
</form>
</center>
</table>
</body>
</html>

Parte in Php
<html>
<head>
<title> Scrittura dei dati angrafici </title>
</head>
<body>
<?php
//Inizializzazione delle variabili
$cognom=$_POST['cognom'];
$indiri=$_POST['indiri'];
$profes=$_POST['profes'];
$datnas=$_POST['datnas'];
$locali=$_POST['locali'];
$email=$_POST['email'];
//Apertura del file anagrafe2.txt in append
$fp=fopen("anagrafe2.txt","a");
//Verifica che il file esista
if($fp) {
/*Blocco del file anagrafe2.txt ($fp)
per la scrittura dei dati.*/
flock($fp,2);
$nl=chr(13).chr(10);
fputs ($fp, "$cognom|$indiri|$profes|$datnas|$locali|$email|$nl");
//Sblocco del file ($fp) cloccato x la scrittura
flock($fp,3);

//Chiusura del file
fclose($fp);
}
?>
Torna al form <a href="scrivi_1.php"> per l'immissione dei dati.
</body>
</html>

Nessun commento:

Posta un commento