Search This Blog

file append in php

<?php

if(isset($_POST['name'])&&isset($_POST['age'])&&isset($_POST['fname']))
{
  $name=$_POST['name'];
  $age=$_POST['age'];
  $fname=$_POST['fname'];
  if(!empty($name)&&!empty($age)&&!empty($fname))
  {
      $file=$_POST['fname'].'.txt';
      if(file_exists("$file"))
      {
      $hand=fopen("$fname".'.txt','a');
      fwrite($hand,$name." ");
      fwrite($hand,$age."\r\n");
      fclose($hand);
      }
      else
      echo 'file not exist';
  }
  else
      echo 'all fielsd are not filled';

}

?>

<form action="file-append.php" method="POST">
name : <input type="text" name="name">
age  : <input type="text" name="age">
file name : <input type="text" name="fname">
.txt
<input type="submit" value="submit">
</form>

output :

note :
1) try with no input datat and click submit button
2) try with don't fill all text boxes and click on submit button
3) try with fill all text boxes and click on submit button
4)check  " test.txt " file

Share Links

Related Posts Plugin for WordPress, Blogger...