I have made a form, which adds some lines inside another file, called data.php. Here is the code:
<?php
if (isset($_POST['post'])){
// GET EMAIL
$post_text = $_POST["post_text"];
if($post_text == '') $error = "Post content is empty";
$filename = getcwd() . "data.php";
$line_i_am_looking_for = 1;
$lines = file( $filename , FILE_IGNORE_NEW_LINES );
$lines[$line_i_am_looking_for] = $post_text;
file_put_contents( $filename , implode( "\n", $lines ) );
?>
<html>
<head>
</header
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php
if ($error) {
?>
<script type="text/javascript">
// close the errordiv in secs
window.setTimeout("close();", 4000);
function close(){
document.getElementById("errordiv").style.display="none";
}
</script>
<?php
}
?>
<div id="errordiv" style="display:block; color:#FF3535">
<b><?php if($error) echo $error; ?></b>
</div>
Email:
<input name="post_text" size="30" type="text">
<input class="button" value="Submit" type="submit" name="post">
</form>
</body>
</html>
When I open index.php, enter some words in the text box and submit the form, I want to write the entered text in the second line of data.php file. But it's not working.