I need to clarify, I am still new to PHP and have no Idea how Input/Output works with Array. The intention of the code is to add a list of data. te[0] is meant to be an example. Starting from te[1] is where you can add your own data and save it on to the .txt file and on the website on the table as well. I get errors such as "Undefined Array key" or "Trying to access array offset on value of type null". Can anyone further enlighten me?
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Input</title>
</head>
<body>
<?php
$te = array();
$te[0]['Date'] = 20210808;
$te[0]['Name'] = "Warcraft";
$te[0]['Place'] = "Vienna";
if (isset ($_GET['Date']))
{
$handle = fopen("sampleOutput.txt", "w+");
fwrite($handle, $_GET[$te[1]['Date']]);
fwrite($handle, "|");
fwrite($handle, $_GET[$te[1]['Name']]);
fwrite($handle, "|");
fwrite($handle, $_GET[$te[1]['Place']]);
fclose($handle);
echo "Thank you";
exit;
}
function date_de($date)
{
$Date = date_create($date);
print date_format($Date, 'd.m.Y');
}
?>
<form action="sampleInput.php" method="get">
<p>Add a date:<br>
<input type="Date" name="Datum" value="<?php date_de($te[1]['Date']); ?>"></p>
<p>Add a name:<br>
<input type="Text" name="Band" value="<?php $te[1]['Name']; ?>"></p>
<p>Add a place:<br>
<input type="Text" name="Ort" value="<?php $te[1]['Place']; ?>"></p>
<input type="Submit" name="" value="Save">
</form>
<br>
<table>
<tr>
<td>1.</td>
<td><?php date_de($te[0]['Date']); ?></td>
<td><?php echo $te[0]['Name']; ?> </td>
<td><?php echo $te[0]['Place']; ?></td>
</tr>
<tr>
<td>2.</td>
<td><?php $z1 = fgets(date_de($te[1]['Date'])); echo ($z1);?></td>
<td><?php $z2 = fgets($te[1]['Name']); echo ($z2);?></td>
<td><?php $z3 = fgets($te[1]['Place']); echo ($z3);?></td>
</tr>
</table>
</body>
</html>