Hi,
I'm a PHP newbie and I'm stumped on a piece of making a form submit.
A little background:
- I am trying to make the if(isset($_POST)) dynamic since I will have many pages that have the same basic function but will place data into different tables/fields.
- I am able to get the form to submit correctly if I don't use any variables, and hard code something like: $name1 = $_POST['name1'];
The process works like this:
1) A form is created that automatically is given a name. For example:I should note that according to the HTML source code, there is no issue assigning the correct name and the form looks correct. I will also note that with any given form, there maybe 1 or 5 ...or some other number of fields.Code:<div class='form-group'><textarea class='form-control' rows='5' name='{$name1}'>{$sampleData}</textarea></div>.
2) I send the information via post and this is where it is getting tricky. What I have is below:
So you will first notice that $name1 = $_POST['name1']; and the column names are hard coded. Is there a good way to pull my automatically generated form names into $_POST? How about automatically pulling in the column names?Code:if(isset($_POST['submit'])){ $name1 = $_POST['name1']; $name2 = $_POST['name2']; $name3 = $_POST['name3']; $nextPage = $_POST['nextpage']; $date = date('Y-m-d H:i:s'); $userid = 10; if(isset($_POST['submit'])) { header("Location: /pages/$nextPage"); $query = "INSERT INTO tablename (id, field1,field2, field3, lotdrivewaydate) "; $query .= "VALUES ($userid, '$name1', '$name1', '$name2', '$name3') "; $result = mysqli_query($connection, $query); echo "$nextPage"; if(!$result) { die("QUERY FAILED" . mysqli_error($connection)); } } }
I've been working on this for quite a while and haven't been able to crack it. Hopefully, this is clear but let me know if I can provide more detail. Thank you in advance for any ideas you all have!



Reply With Quote

Bookmarks