Skip to content

Instantly share code, notes, and snippets.

@techsharif
Created October 8, 2017 06:02
Show Gist options
  • Save techsharif/6516468116ac57754ec85954930ed74f to your computer and use it in GitHub Desktop.
Save techsharif/6516468116ac57754ec85954930ed74f to your computer and use it in GitHub Desktop.
<?php
// for data add
function add_data($id,$name,$phone){
$data = sprintf('%10d%60s%15s',$id,$name,$phone);
$file = fopen('db.txt','a');
fwrite($file,$data);
fclose($file);
}
if (isset($_GET['add-data'])){
$id = $_GET['id']+0;
$name= $_GET['name'];
$phone = $_GET['phone'];
add_data($id,$name,$phone);
}
?>
<?php
// for data show
$file = fopen('db.txt','r');
$filesize = filesize('db.txt');
$data = fread($file,$filesize);
fclose($file);
echo $data;
$ln = strlen($data);
for ($i=0; ; $i++){
$start = $i*85;
$extra = 85;
if ($start+$extra > $ln){
break;
}
$student_info = substr($data,$start,$extra);
$id =trim(substr($student_info,0,10));
$name =trim(substr($student_info,10,60));
$phone =trim(substr($student_info,70,15));
echo "<br>id: $id - Name: $name - Phone: $phone";
}
?>
<form action="" method="GET">
<input type="number" name="id" placeholder="id">
<input type="text" name="name" placeholder="name">
<input type="text" name="phone" placeholder="phone">
<input type="submit" name="add-data" value="Add">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment