2016-01-06 57 views
1

我有以下代码。这在我的管理面板上用于管理员将其笔记放入其他管理员可以读取它。我不想将它存储在数据库中。窗体不保存到PHP文件

问题是表单没有保存文本在textarea中。

<?php 
IF (ISSET($_POST["submit"])) { 
$string = '<?php 
$notes = "'. $_POST["notes"]. '"; 
?>'; 

$fp = FOPEN("includes/notes.php", "w"); 
FWRITE($fp, $string); 
FCLOSE($fp); 
echo '<div class="ok">' . $lang["done"] . '</div>'; 
} 

include("includes/notes.php"); 
?> 
<form action="" method="post" id="notesform"> 
<textarea placeholder="Admin notes" class="notes" id="notes"><?php echo $notes; ?></textarea> 
<input type="submit" value="OK"> 
</form> 

什么问题?我怎样才能解决这个问题?我曾在Google上尝试过大部分建议,但它一直在发生!

+0

更改''转到''那么你先IF测试实际上会在'$ _POST'中找到按钮名称。 – RiggsFolly

+0

顺便说一句:在camelcase中编写函数等是很可怕的。难以阅读的其他开发人员可以加入你的团队等。想想看。 –

+1

@bub你的意思是大写.. camelCase就好.. –

回答

3

您没有给name属性提交按钮。

当我们向PHP提交表单时,只有元素获得name属性。

所以,你的代码是不是进入:

IF (ISSET($_POST["submit"])) { // Not satisfying this condition. 

更正代码:

<input type="submit" value="OK" name="submit"> 

申请文本区域也同样如此。

+0

Ooooh当然!我试图在'form'标签之前加入,但那不起作用。谢谢你的帮助! –

+0

@Pupil,是否可以在这里获得文本区域值而不给出name =“notes”? –

+0

是的,@AmitRajput,你是对的。我会纠正我的答案。谢谢你的收获。 – Pupil

2

您没有给文本区域提供name =“notes”并提交按钮名称。这是完整正确的代码。试试这个:

<?php 
IF (ISSET($_POST["submit"])) { 
$string = $_POST["notes"]; 

$fp = FOPEN("includes/notes.php", "w"); 
FWRITE($fp, $string); 
FCLOSE($fp); 
echo '<div class="ok">' . $lang["done"] . '</div>'; 
} 

include("includes/notes.php"); 
?> 
<form action="" method="post" id="notesform"> 
<textarea placeholder="Admin notes" class="notes" name="notes" id="notes"><?php echo $notes; ?></textarea> 
<input type="submit" name="submit" value="OK"> 
</form> 
+0

@john是否适合你? –

+0

是的,我现在正在工作,你上面的那个人快一点。不过,感谢您的帮助。非常感谢 –

+0

谢谢......干杯! :-) –