<?php
include 'config.php';
include 'connect.php';
$conn = @mysql_connect($host,$username,$password) or die (mysql_error());
$sel = @mysql_select_db($db) or die (mysql_error());
if(!isset($_POST['aggiorna'])) {
echo "<form action=\"" . htmlspecialchars($_SERVER['PHP_SELF']). "\" method=\"post\">";
$result = mysql_query("SELECT * FROM lettera_del_presidente")or die(mysql_error());
if(mysql_num_rows($result)>0){
while ($row = mysql_fetch_array($result)) {
if($row['id'] !=""){
echo "<textarea name=\"testo[".$row['id']."]\" id=\"testo[".$row['id']."]\">".$row['testo']."</textarea><br>";
}
}
}
echo "<br/><input type=\"submit\" name=\"aggiorna\" value=\"aggiorna\" />";
echo "</form>";
}else{
$test_array=$_POST['testo'];
if(is_array($test_array)){
foreach($test_array as $chiave => $testo){
$query=mysql_query("UPDATE lettera_del_presidente SET testo='$testo' WHERE id=$chiave") or die(mysql_error());
}
echo "aggiornamento eseguito";
}else{
echo "non hai inviato testi";
}
echo "<meta http-equiv='Refresh' content='4; URL=".htmlspecialchars($_SERVER['PHP_SELF'])."'>";
}
?>