HTML Form to post on php page

馋奶兔 提交于 2019-12-02 13:29:06
<?php

 $Input = $_POST['element'];

 $FileToUpdate = "home.php";
 $fh = fopen($FileToUpdate , 'w') or die("can't open file");

 fwrite($fh, $Input);

 fclose($fh);     

 ?>

The code above will do what you wish, but will overwrite the page (to append see this reference). But really I think you need to start from basics with a good PHP Tutorial.

This should do what you want:

<?php
    $filename = "/path/to/home.php";
    $file = fopen( $filename, "w" );
    if( $file == false ) {
       echo ( "Error in opening new file" );
       exit();
    }
    fwrite( $file, $_POST['element'] );
    fclose( $file );
?>

You can read more about file I/O here.

You can use the php $_POST var to fetch the data from a form post.

For example if you want to fetch the field named "element" you can use $_POST['element']

Try the code below to display the text which was typed into the textarea. The code goes into home.php

<?php
 echo $_POST['element'];
?>

Likewise you can fetch all required data. Hope this helps. Please go through http://www.w3schools.com/php/php_post.asp for more information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!