1

I have a form as shown below.

<form role="form-horizontal" method="post" action="pacific.php" style="width 70%">
<div class="input-group input-group-lg">
<span class="input-group-addon" id="sizing-addon1">Name:</span>
<input type="text" class="form-control" placeholder="Name" id="name" aria-describedby="sizing-addon1">
</div>
<button type="submit" class="btn btn-default">Next ></button>
</form>

It submits name to pacific.php. On pacific.php I have php code first getting the input from name and then I have an echo statement as show below.

<?php
$n = $_POST["name"];
echo "Hello, $n.";
?>

Yet on the page, all it echos is "Hello, .". I'd like it to echo "Hello, (persons name)."

htcsml4792
  • 61
  • 8

3 Answers3

1

You forgot to add name to the desired input

<form role="form-horizontal" method="post" action="pacific.php" style="width 70%">
<div class="input-group input-group-lg">
<span class="input-group-addon" id="sizing-addon1">Name:</span>
<input type="text" class="form-control" placeholder="Name" id="name" aria-describedby="sizing-addon1" name="name">
</div>
<button type="submit" class="btn btn-default">Next ></button>
</form>
Neobugu
  • 333
  • 6
  • 15
0
<input type="text" class="form-control" placeholder="Name" id="name" aria-describedby="sizing-addon1">

change to

<input type="text" class="form-control" placeholder="Name" name="name" id="name" aria-describedby="sizing-addon1">

you need to use name attribute, while posting a form PHP requests names of inputting elements.

ameenulla0007
  • 2,663
  • 1
  • 12
  • 15
0

Your code has to be this way: name="name" is required to capture data using post method.

<form role="form-horizontal" method="post" action="pacific.php" style="width 70%">
<div class="input-group input-group-lg">
<span class="input-group-addon" id="sizing-addon1">Name:</span>
<input type="text" class="form-control" placeholder="Name" name="name" id="name" aria-describedby="sizing-addon1">
</div>
<button type="submit" class="btn btn-default">Next ></button>
</form>


<?php
$n = $_POST["name"];
echo "Hello, $n.";
?>
Fakhruddin Ujjainwala
  • 2,493
  • 17
  • 26