I’ve got some issues with my PHP code. I want to load two .txt to edit with the browser (chrome, ie, any) and saves changes through just one button. Until now, I can do it with multiple buttons, but thats risky cos if you forget to save one change you lose it.
Here is my code:
<?php
$fn = "../txt/example.txt";
if (isset($_POST['agenda1a']))
{
$content = stripslashes($_POST['agenda1a']);
$fp = fopen($fn,"w") or die ("Error");
fputs($fp,$content);
fclose($fp) or die ("Error");
}
?>
<div class="editor">
<div class="editor_titulo">Agenda 1</div>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
<textarea name="agenda1a" cols="55" rows="25" class="editor_texto"><?php readfile($fn); ?>
</textarea>
<input name="submit" type="submit" class="btn_entrar" id="btn_guardar" value=" Guardar este menú ">
</form>
</div>
<?php
$fn = "../txt/example2.txt";
if (isset($_POST['agenda1b']))
{
$content = stripslashes($_POST['agenda1b']);
$fp = fopen($fn,"w") or die ("Error");
fputs($fp,$content);
fclose($fp) or die ("Error");
}
?>
<div class="editor">
<div class="editor_titulo">Agenda 2</div>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
<textarea name="agenda1b" cols="55" rows="25" class="editor_texto"><?php readfile($fn); ?>
</textarea>
<input type="submit" class="btn_entrar" id="btn_guardar" value=" Guardar este menú ">
</form>
</div>
Is there any way to do it?
You’ll need to place the
<textarea>elements under the same<form>. This can be done with the code you’ve presented, but you’ll likely have to make some styling changes, as one of the.editorelements is removed.