Ciao,
da un thread ho copiato vilmente del codice ma, ahime, non funzia.
Mi appare sempre:
Parse error: parse error, unexpected T_FOREACH in C:\www\provabestiale\c.php on line 50
Chi è così bravo da dirmi dove sbaglio?
Il codice è questo qua:
<?
if (!isset($_POST['Invia']))
{
?>
<html>
<head>
<meta http-equiv="Content-Language" content="it">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>commenti</title>
</head>
<body>
<form method="POST" action="index2.php">
<table border="0" width="500" align="center" style="border-collapse: collapse">
<tr>
<td width="11%">nome</td>
<td width="87%"><input type="text" name="dato[]" size="20"></td>
</tr>
<tr>
<td width="11%">provenienza</td>
<td width="87%"><input type="text" name="dato[]" size="20"></td>
</tr>
<tr>
<td width="11%">opinione</td>
<td width="87%"><textarea rows="6" name="dato[]" cols="50"></textarea></td>
</tr>
<tr>
<td colspan="2">
<p align="center"><input type="submit" value="Invia" name="Invia"></td>
</tr>
</table>
</form>
</body>
</html>
<?
}
else
{
foreach ($_POST['dato'] as $val)
{
if (trim($val)=="")
{
echo "completare tutti i campi";
header("refresh:5;url=c.php");
die();
}
}
}
$string="";
$file=fopen("text.txt","a+") //apre il file in append, se non esiste lo crea
foreach ($_POST['dato'] as $val)
{
$string.="|".$val; // costruisce la stringa |dato1|dato2|dato3|dato4 ecc...
}
$string=substr($string,1); // elimina il primo |
fwrite ($file,$string); //scrive la stringa
fclose ($file); //chiude il file
?>