codice:
<html>
<head>
</head>
<body>
<?php
include "db_connect.php";
session_start();
$this_pg = "show_comm.php?id_news=$id_news&";
$insert_comm = <<<EOINSERTCOMM
<form method="post" action="$this_pg">
Autore: <input type="text" name="autore" size="30">
Commento: <textarea name="commento" rows="5" cols="30"></textarea>
<input type="submit" name="submit" value="Invia">
</form>
EOINSERTCOMM;
$id_news = $_GET['id_news'];
$_SESSION['idnews']=$_GET['id_news'];
$newsid = $_SESSION['idnews'];
if (!$_POST['submit']){
$mess = $insert_comm;
}elseif ($_POST['submit'] == 'Invia'){
if (!$_POST['autore'] || !$_POST['commento']){
$mess = "Hai dimenticato di inserire tutti i dati necessari.".$insert_comm;
}else{
$connection = mysql_connect($hostname, $dbuser, $dbpassword);
mysql_select_db($db, $connection);
$autore = $_POST['autore'];
$commento = $_POST['commento'];
$as_commento = addslashes($commento);
$ins_query = "INSERT INTO news_comments (ID_comment, ID_news, commento, autore, data_comm) VALUES (NULL, '$newsid', '$as_commento', '$autore', now())";
$result = mysql_query($ins_query);
if (mysql_affected_rows() ==1){
$mess = "Inserimento avvenuto con successo.";
} else {
$mess = "Si e' presentato un problema durante l'inserimento.".$insert_comm;
}
}
}
include "comm_sito.php";
echo "
<a href=show_comm.php?id_news=$newsid&showall=1>Mostra tutti i commenti.</a>";
echo $mess;
echo "
<a href=news_sito(1).php>Indietro</a>";
?>
</body>
</html>
Se manca qualche parentesi e' perche' stavo provando a modificarlo.