mercoledì 8 giugno 2011

scrivi_1.php

<html>
<head>
<title>Scrittura dati anagrafici</title>
</head>
<body>
<center>
<h2>Gestione dati anagrafici</h2>
<table border='0'>
<form action="scrivi_2php" method="POST">
<tr>
<td>Cognome e nome</td>
<td>Indirizzo</td>
</tr>
<tr>
<td><input name="cognom" maxlenght="30" size="30"></td>
<td><input name="indiri" maxlenght="50" size="50"></td>
</tr>
<tr>
<td>Professione</td>
<td>Data di nascita</td>
</tr>
<tr>
<td><input name="profes" maxlenght="30" size="30"></td>
<td><input name="datnas" maxlenght="10" size="10"></td>
</tr>
<tr>
<td>Localit&agrave;</td>
<td>Posta elettronica</td>
</tr>
<tr>
<td><input name="locali" maxlenght="30" size="30"></td>
<td><input name="email" maxlenght="50" size="50"></td>
</tr>
</tr></tr></tr></tr></tr></tr>
<tr>
<td><input type="submit" value="Invia"></td>
<td><input type="reset" value="Cancella"></td>
</tr>
</form>
</table>
</center>
</body>
</html>


scrivi_2.php


<html>
<head>
<title>Scrittura dati anagrafici</title>
</head>
<body>
<?php
// Iniializzazione 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 appen
$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 anagrafe2.txt ($fp)
bloccato per la scrittura dei dati.*/
flock($fp,3);
// Chiusura del file anagrafe2.txt
fclose($fp);

}
?>
Torna al form <a href="scrivi_1.php"> per l'emissione dei dati
</body>
</html>

Nessun commento:

Posta un commento