I have a simple form in HTML that receives the values for a person's last name and first name. Then I use a PHP file that submits this form into a MySQL database.
I want to make a third variable called 'name' that consists of 'firstname' and 'lastname' together, and I want this 'name' to be submitted to the database.
However, I also have to display 'name' as the user types his last name and first name. For this, I'm using the 'oninput' and 'output' tag combinations. This is a shortened version of my HTML file:
<form
action="file.php"
method="post"
oninput="name.value=lastname.value + space.value + firstname.value">
<input type="text" id="space" value=" ">
<output id="name" name="name">
<input type="text" class="text" name="lastname">
<input type="text" class="text" name="firstname">
<input type="submit" id="submit" name="submit">
</form>
And this is what I'm doing in the PHP file:
$name= $_POST['name'];
$sql = "INSERT INTO table1 (name) VALUES ('$name')";
I think the problem is that I can't simply submit the value of an output? Because this works fine if I want to submit 'lastname' or 'firstname' which are both inputs.
Please help!
PS: Is there an easier way to include a space on the 'oninput' part?