codice:
<?php
function renderForm($userEmail, $password, $societa, $nome, $cognome, $via, $numero, $cap, $citta, $provincia, $codicefiscale, $piva, $ref, $telefono, $cell, $sped_via, $sped_numero, $sped_cap, $sped_citta, $sped_provincia, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Nuovo Record</title>
</head>
<body>
<?php
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<div>
<strong>Dati anagrafica cliente Per fatturazione<br>
Email utente: *</strong> <input type="text" name="userEmail" value="<?php echo $userEmail; ?>" /><br/>
<strong>Password utente: *</strong> <input type="text" name="password" value="<?php echo $password; ?>" /><br/>
<strong>Nome Società : *</strong> <input type="text" name="societa" value="<?php echo $societa; ?>" /><br/>
<strong>Nome Utente: *</strong> <input type="text" name="nome" value="<?php echo $nome; ?>" /><br/>
<strong>Cognome Utente: *</strong> <input type="text" name="cognome" value="<?php echo $cognome; ?>" /><br/>
<strong>via: *</strong> <input type="text" name="via" value="<?php echo $via; ?>" /><br/>
<strong>numero civico: *</strong> <input type="text" name="numero" value="<?php echo $numero; ?>" /><br/>
<strong>cap: *</strong> <input type="text" name="cap" value="<?php echo $cap; ?>" /><br/>
<strong>citta: *</strong> <input type="text" name="citta" value="<?php echo $citta; ?>" /><br/>
<strong>provincia: *</strong> <input type="text" name="provincia" value="<?php echo $provincia; ?>" /><br/>
<strong>codice fiscale: *</strong> <input type="text" name="codicefiscale" value="<?php echo $codicefiscale; ?>" /><br/>
<strong>partita iva: *</strong> <input type="text" name="piva" value="<?php echo $piva; ?>" /><br/>
<strong>referente: *</strong> <input type="text" name="ref" value="<?php echo $ref; ?>" /><br/>
<strong>telefono: *</strong> <input type="text" name="telefono" value="<?php echo $telefono; ?>" /><br/>
<strong>cellulare: *</strong> <input type="text" name="cell" value="<?php echo $cell; ?>" /><br/>
<br>
Dati per la spedizione cliente<br>
<br/>
<strong>sped via: *</strong> <input type="text" name="sped_via" value="<?php echo $sped_via; ?>" /><br/>
<strong>sped numero Civico: *</strong> <input type="text" name="sped_numero" value="<?php echo $sped_numero; ?>" /><br/>
<strong>sped cap: *</strong> <input type="text" name="sped_cap" value="<?php echo $sped_cap; ?>" /><br/>
<strong>sped citta: *</strong> <input type="text" name="sped_citta" value="<?php echo $sped_citta; ?>" /><br/>
<strong>sped provincia: *</strong> <input type="text" name="sped_provincia" value="<?php echo $sped_provincia; ?>" /><br/>
<input type="submit" name="submit" value="Invia">
</div>
</form>
</body>
</html>
<?php
}
// connessione al database
include('connect-db-clienti.php');
// verifica se il modulo è stato inviato. Se lo è, inizia a elaborare il modulo e lo salva nel database
if (isset($_POST['submit']))
{
// ottenere i dati del modulo e verific che siano validi
$userEmail = mysql_real_escape_string(htmlspecialchars($_POST['userEmail']));
$password = mysql_real_escape_string(htmlspecialchars($_POST['password']));
$societa = mysql_real_escape_string(htmlspecialchars($_POST['societa']));
$nome = mysql_real_escape_string(htmlspecialchars($_POST['nome']));
$cognome = mysql_real_escape_string(htmlspecialchars($_POST['cognome']));
$via = mysql_real_escape_string(htmlspecialchars($_POST['via']));
$numero = mysql_real_escape_string(htmlspecialchars($_POST['numero']));
$cap = mysql_real_escape_string(htmlspecialchars($_POST['cap']));
$citta = mysql_real_escape_string(htmlspecialchars($_POST['citta']));
$provincia = mysql_real_escape_string(htmlspecialchars($_POST['provincia']));
$codicefiscale = mysql_real_escape_string(htmlspecialchars($_POST['codicefiscale']));
$piva = mysql_real_escape_string(htmlspecialchars($_POST['piva']));
$ref = mysql_real_escape_string(htmlspecialchars($_POST['ref']));
$telefono = mysql_real_escape_string(htmlspecialchars($_POST['telefono']));
$cell = mysql_real_escape_string(htmlspecialchars($_POST['cell']));
$sped_via = mysql_real_escape_string(htmlspecialchars($_POST['sped_via']));
$sped_numero = mysql_real_escape_string(htmlspecialchars($_POST['sped_numero']));
$sped_cap = mysql_real_escape_string(htmlspecialchars($_POST['sped_cap']));
$sped_citta = mysql_real_escape_string(htmlspecialchars($_POST['sped_citta']));
$sped_provincia = mysql_real_escape_string(htmlspecialchars($_POST['sped_provincia']));
// controlla che entrambi i campi vengono inseriti
if ($userEmail == '' || $password == '' || $societa == '' || $nome == '' || $cognome == '' || $via == '' || $numero == '' || $cap == '' || $citta == '' || $provincia == '' || $codicefiscale == '' || $piva == '' || $ref == '' || $telefono == '' || $cell == '' || $sped_via == '' || $sped_numero == '' || $sped_cap == '' || $sped_citta == '' || $sped_provincia == '')
{
// genera messaggio di errore
$error = 'ERRORE: Tutti i campi contrassegnati sono obbligtori!';
// se uno dei due campi è vuoto, visualizzo di nuovo il modulo
renderForm($userEmail, $password, $societa, $nome, $cognome, $via, $numero, $cap, $citta, $provincia, $codicefiscale, $piva, $ref, $telefono, $cell, $sped_via, $sped_numero, $sped_cap, $sped_citta, $sped_provincia, $error);
}
else
{
// salva i dati nel database
mysql_query("INSERT utenti SET userEmail='$userEmail', password='$password', societa='$societa', nome='$nome', cognome='$cognome', via='$via', numero='$numero', cap='$cap', citta='$citta', provincia='$provincia', codicefiscale='$codicefiscale', piva='$piva', ref='$ref', telefono='$telefono', cell='$cell', sped_via='$sped_via', sped_numero='$sped_numero', sped_cap='$sped_cap', sped_citta='$sped_citta', sped_provincia='$sped_provincia'")
or die(mysql_error());
// una volta salvato, si viene reindirizzati alla pagina di visualizzazione
header("Location: view.php");
}
}
else
// se il modulo non è stato inviato, visualizzare il modulo
{
renderForm('','','');
}
?>