I'm filling out a form in HTML, that I want to pass as an array argument to a function in PHP.
Here's how it looks like.
Inside insert function later on I'm going to be passing those values to add record into my database table, but for now on there's echoing implemented for debuggnig purposes.
<?php
echo '
Dodaj koncert
<form action="" method="post">
Nazwa klubu: <input type="text" name="data[0]"><br>
Adres Klubu: <input type="text" name="data[1]"><br>
Nazwa zespolu: <input type="text" name="data[2]"><br>
Ilosc czlonkow: <input type="text" name="data[3]"><br>
Data koncertu: <input type="text" name="data[4]">
<input type="submit" name="dodaj_koncert" value="Dodaj">
</form> ';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
insert(Koncerty, data);
}
function insert($table, $data)
{
echo $data[2] . '<br>';
echo $data[3] . '<br>';
echo $table;
}
?>
I'm sure there's something wrong with the data that I need to be an array and it's either how I assign values from input form or how I process it. How do I make it work as an array and can read filled form from within the insert function?
empty()checking later on. Does it do that much of a change? If changed to$_POSTwill I not need checking it later on, or what will be happening?Koncertyis a table in database, whiledatashould be PHP array.$tablewill then be executed inside functioninsert()to use this table and insert data from array into it.