I have some problems to be able to save and open text files with PHP, I am using the following code:
<?php
if($_POST['submit']){
$open = fopen("frases/frase_del_dia.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "<p>El Contenido se Actualizo!</p>";
$file = file("frases/frase_del_dia.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("frases/frase_del_dia.txt");
echo "<form action='".$_SERVER['PHP_SELF'] ."' method='post'>";
echo "<br><textarea name='update' style='height:250px'>";
foreach($file as $text) {
echo $text;
}
echo "</textarea><br>";
echo "<input name='submit' type='submit' value='Update' />\n
</form>";
}
?>
As a result I get the following error:
Notice: Undefined index: submit in /var/www/html/relaxedmind/editor.php on line 2
and I do not see what the file frase_del_dia.txt
has in <textarea></textarea>
.
The content of my file frase_del_dia.txt is as follows (one sentence for each line):
Solo hay una felicidad en la vida – amar y ser amado
Cuanto más hacemos, más podemos hacer
Cáete siete veces y levántate ocho
El fracaso es éxito si aprendemos de el
Todo tiene belleza, pero no todo el mundo puede verla
El hombre necesita dificultades porque son necesarias para disfrutar el éxito
Es impresionante. La vida cambia muy rápido, de un modo positivo, si la dejas
Tienes que pensar de todas formas. ¿Por qué no pensar en grande?
Rodeate de gente positiva y serás una persona positiva
Cuando tienes un sueño tienes que agarrarlo y nunca dejarlo ir
I would appreciate if you can give me a hand, Thanks!