I am trying to take data that a user inputs into a form, created in blade, and transport that data to my controller. At that point I can use a function in my controller to write the data into MySQL.
Here is the code for the form which I have in my blade file.
<form action="{{ route("users") }}" method="post">
<input type ="form" id="firstname"> firstname </input> <br>
<input type ="form" id="lastname"> lastname </input> <br>
<input type="form" id="email"> email </input> <br>
<input type="form" id="userlevel"> userlevel </input> <br>
<input type="form" id="password"> password </input> <br>
<br> <br>
<button type="submit"> Submit
</button>
</form>
Here is the code in my controller which writes data into MySQL. The code works when I am using dummy data, instead of the $name
and $lastname
variables.
public function users()
{
$name = $_POST["firstname"];
$lastname = $_POST["lastname"];
DB :: table("newUsers") -> insertGetId
(
array("firstname" => $name, "lastname" => $lastname, "email" => "test")
);
return view("pages.users");
}
I am currently getting an error that says
Undefined index: firstname
Ideally what I want to happen is for whatever the user entered for firstname and lastname to be written into my MySQL table.