I have included here a PHP file I have written. I figured out how to save information to a file when the user give's his or her name, but I can't open the file and get the certain lines of info i want.
So next time this user opens this file it will have his/her data in the value.. Understand?
Php code:
<?
if (!$submit)
{
?>
<?
// Open File.txt
$fp = fopen("file.txt","'w+");
$details = array("$name", "$age");
$name = $details[0];
$age = $details[1];
fclose ($fp)
?>
<form action="index.php" method="POST">
<font size=2>
Name: <input type="text" name="name" value="<? echo $details[0] ?>" size="18"><br>
Age: <input type="text" name="age" value="<? echo $details[1] ?>" size="18"></font>
<input type="submit" name="submit" value="Submit!">
</form>
<?
}
else
{
?>
<?php
// Give commands
$name = "$name\n";
// Open File.txt
$fp = fopen("file.txt","w");
// Write Data
fwrite($fp, $name);
fwrite($fp, $age);
// Put in array
$details = array("$name", "$age");
// Close File
fclose ($fp)
?>
Thanks for the submission <? echo $details[0] ?>! You are <? echo $details[1] ?> years old! 😉
<?
}
?>