Codice PHP:
<?php
$con=mysql_connect();
if(!$con){
die('Impossibile connettersi a: ' . mysql_error());
}
mysql_select_db();
$sql="INSERT INTO prodotto (id, nome, prezzo, descrizione) VALUES ('$_POST[id]','$_POST[nome]','$_POST[prezzo]','$_POST[descrizione]')";
if (isset($_POST['upload_pdf'])){
$pdfDirectory = "prodotti/";
$filename = basename( $_FILES['filepdf']['name'], ".pdf");
$filename = preg_replace("/[^A-Za-z0-9_-]/", "", $filename).".pdf";
if(move_uploaded_file($_FILES['filepdf']['tmp_name'], $pdfDirectory.$filename)) {
$pdfWithPath = $pdfDirectory.$filename;
}
}
$descrizione=nl2br($_POST[descrizione]);
$filename=mysql_real_escape_string($filename);
$fp=fopen($_POST[nome].'.php','w');
fwrite($fp,
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>La Serenissima - Scheda prodotto</title>
<link rel=\"shortcut icon\" href=\"images/logo_short.PNG\" type=\"image/x-icon\" />
<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />
</head>
<body class=\"corpo\">
<div id=\"container\">
<div id=\"header\">
<img src=\"images/logo.PNG\" alt=\"La Serenissima\" style=\"width:303;height:293;margin-top:20px;margin-bottom:10px;\" />
</div>
<div id=\"tmenu\">
<ul id=\"topmenu\">[*]<a href=\"index.php\">HOME</a>[*]<a id=\"click\" href=\"prodotti.php\">PRODOTTI</a>[*]<a href=\"eventi.php\">EVENTI</a>[*]<a href=\"chisiamo.php\">CHI SIAMO</a>[*]<a href=\"contatti.php\">CONTATTI</a>[/list]
</div>
<div id=\"main\">
<div>
<h3>Scheda prodotto</h3>
<u>$_POST[nome]</u>
</div>
<a href=\"prodotti.php\"><img src=\"images/back.png\" title=\"Prodotti\" /></a>
    <a href=\"$pdfWithPath\" target=\"_blank\"><img src=\"images/guarda.png\" title=\"Anteprima\" /></a>
    <a href=\"acquista.php\"><img src=\"images/compra.png\" title=\"Acquista\" /></a>
<a href=\"$pdfWithPath\" target=\"_blank\">Visualizza immagine del prodotto</a>
Prezzo equivalente ad una quantità: $_POST[prezzo] €
$descrizione
</p>
</div>
<div id=\"footer\">
<a href=\"admin.php\">[b]Amministrazione[/b]</a> | [b]Powered by[/b] <a href=\"http://francescopassanante.eu\" target=\"_blank\">Francesco Passanante</a></p>
</div>
</div>
</body>");
fclose($fp);
if(!mysql_query($sql,$con)){
die('Errore: ' . mysql_error());
}
mysql_close($con);
header("Location:prodotti.php");
?>