Codice PHP:
<? session_start();
$_SESSION['nomes'] = $_POST['nome'];
$_SESSION['emails'] = $_POST['email'];
$_SESSION['urls'] = $_POST['url'];
$_SESSION['commentos'] = $_POST['commento'];
$_SESSION['ids'] = $_POST['id'];
$_SESSION['votos'] = $_POST['voto'];
$_SESSION['nomedb'] = $_POST['nomedb'];
?>
<html>
<head>
<?php
include ("config.inc.php");
$db = mysql_connect($db_host, $db_user, $db_password);
if ($db == FALSE)
die ("Errore nella connessione. Controllare i parametri all'interno del file confing.inc.php");
mysql_select_db ($db_name, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
function is_email($email) {
if (eregi("^([a-z0-9_\.-])+@(([a-z0-9_-])+\\.)+[a-z]{2,6}$", trim($email)))
return 1;
else
return 0;
}
function CodeUrl($url) {
if (eregi("^(www\.|[url]http://www\.[/url])[a-z0-9_\.-]+(\.)[a-z]{2,6}$", trim($url)))
return 1;
else
return 0;
}
if ($_POST[nomedb]=='narrativa') {
$tabella_commenti='commenti_narrativa';}
if ($_POST[nomedb]=='fumetti') {
$tabella_commenti='commenti_fumetti';}
if ($_POST[nomedb]=='film') {
$tabella_commenti='commenti_film';}
?>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
if (($_POST[nome]=="") or ($_POST[commento]=="") or ($_POST[voto]=="")) {
echo "Non hai compilato tutti i campi obbligatori!
";
}
if ($_POST[email] =="") {}
else {
if (is_email($_POST[email])){}
else
{
echo "Email non corretta!";
}
}
if ($_POST[url] =="") {}
else {
if ($_POST[url]!="") {
if (CodeUrl($_POST[url])) {}
else
{
echo "Sito web non valido!";
}
}
}
$commentobr = nl2br ($_POST[commento]);
$search_commento = array ("'", "$", '"', ",", ";", "<?", "?>");
$replace_commento = array ("\'", "\$", '\"', "\,", "\;", "", "");
$replace_commento = str_replace($search_commento, $replace_commento, $commentobr);
$search_nome = array ("'", "$", '"', ",", ";", "<?", "?>");
$replace_nome = array ("\'", "\$", '\"', "\,", "\;", "", "");
$replace_nome = str_replace($search_nome, $replace_nome, $_POST[nome]);
if (($_POST[nome]!="") and ($_POST[commento]!="") and ($_POST[voto]!=0) and (is_email($_POST[email])==true) and (CodeUrl($_POST[url])==true))
{
$query = "INSERT INTO $tabella_commenti (nome, email, url, commento, id_com, voto) VALUES ('$replace_nome', '$_POST[email]', '$_POST[url]', '$commentobr', '$_POST[id]', '$_POST[voto]')";
echo $query;
}
else
{
echo "<meta http-equiv=\"refresh\" content=\"5;URL=insert.php?id=$_POST[id]&nomedb=$_POST[nomedb]\"><H1 align=\"center\">Sei un pirla!</h1><p align=\"center\">Deficiente correggi!</p>";
}
if (mysql_query($query, $db))
{
echo "Il tuo commento è stato inserito correttamente";
echo "<meta http-equiv=\"refresh\" content=\"5;URL=home_page.php\"><H1 align=\"center\">Grazie,</h1><p align=\"center\">Richiesta inviata correttamente</p>";
}
else
{
echo "Errore durante l'inserimento";
}
mysql_close ($db);
?>
</body>
</html>
Grazie mille