0

I thoroughly researched the topic but as a beginner in programming, I want PHP to write data from HTML form to a file. But after series of attempts, I still get an error. Can someone please help by looking at the code ?

Here is the code:

    <form action="oneaccountrecord.php">
<p>Transaction type</p>
<select name='transtype'>
<option name="revenue" value="revenue">Revenue</option>
<option name="expense" value="expense">Expense</option>
</select>
<br>
<p>Date</p>
<input name="date" value="date" type="date" data-date-inline-picker="true"  />
<br>
<p>Description</p>
<input name="description"  type="text"   />
<br>
<p>Amount</p>
<input name="amount"  type="number"   />
<input type="submit" value="Proknjizi">
</form>

Here is the php script:

    <?php



    // Deklaracija  varijabli
    $date = $_POST['date'];
    $description = $_POST['description'];
    $amount = $_POST['amount'];


$file = 'account.txt';

$stampa = $date . $description . $amount .PHP_EOL;

// Write the contents to the file, 
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
file_put_contents($file, $stampa, FILE_APPEND | LOCK_EX);


// Odštampaj dan, datum, mjesec, godinu, vrijeme, AM ili PM
echo date("l jS \of F Y h:i:s A" );
// Štampa da je proknjizio
print "</br>";
print "Zabiljezio sam transakciju.";
print "</br>";

// Kraj 


?>
Daniel
  • 29
  • 2

0 Answers0