i am trying to use a flatfile database just for a basic webpage. i have no mySQL and need a login file to keep certaian things private from guests, and to also have members view a personal page each time they login. i have been trying to use this code
$name = $_POST['name'];
$email = $_POST['email'];
$fp = fopen("data.txt","a");
if(!$fp) {
echo 'Error: Cannot open file.';
exit;
}
fwrite($fp, $name."||".$email."||");
fclose($fp);
to register the users.
But when i open the data file it will not put each user on seperate lines, user||user@user.com||user2||user2@user2.com||user3||user3@user3.com i end up with this.
after all this i have tried to use
<?php
$userinfo = file("data.txt");
echo '<table>';
foreach($userinfo as $key => $val)
{
//explode that data into a new array:
$data[$key] = explode("||", $val);
}
for($k = 0; $k < sizeof($userinfo); $k++)
{
echo '<tr><td>Name:</td><td>'.$data[$k][0].'</td></tr>';
echo '<tr><td>Email:</td><td>'.$data[$k][1].'</td></tr>';
echo '<tr><td colspan=2> </td></tr>';
}
echo '</table>';
?>
<?php
if ($_POST['username'] != $data || $_POST['useremail'] != $data) { ?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" /> <br/><br/>
Enter Name
<input type="text" name="username" />
<br/>
Enter Email
<input type="text" name="useremail" />
<br/>
<br/>
<input type="submit" />
<?php } else { ?>
<?php
echo "Hello $data"; ?>
<?php } ?>
i have tried to use that as a basic login, showing the users at the top and the login box at the bottem.
I am really struggling with this and cannot find anything to help me with it.
Thank you in advance for helping