-1

Hey all from what I can tell my code looks like it should work but it's not. I am not seeing where my error is. When I fill out the form and press submit I am able to get the first variable for name, but phone and email do not show up. Can someone point out where my error(s) are? ` Form Test

<body>

<form action="clientData.php" method="post">
What is your name?
<input type="text" name="name">

<br>
What is your email address?
<input type ="text" email="email">

<br>
What is your phone number?
<input type = "text" phone="phone">
</br>
<input type="submit">


</form>
</body>
</html>`

And here is my clientData.php file where I want to store my variables to insert into my database.

<?php $clientName= $_POST['name']; $clientEmail= $_POST['email']; echo $clientName; echo $clientEmail; ?>

derp
  • 47
  • 1
  • 2
  • 8

3 Answers3

2

You need to change your form like this :

<form action="clientData.php" method="post">
What is your name?
<input type="text" name="name">

<br>
What is your email address?
<input type="text" name="email">

<br>
What is your phone number?
<input type="text" name="phone">
</br>
<input type="submit">

And the PHP :

<?php
$clientName= $_POST['name'];
$clientEmail= $_POST['email'];
$clientPhone= $_POST['phone'];
?>

The HTML attribute which define the index of the value in the POST array is name, so for example to create a field, you need to do it like this :

<input type="text" name="theNameOfTheField">

And to get the result in PHP :

<?php
$fieldValue= $_POST['theNameOfTheField'];
?>
Raphaël Vigée
  • 2,048
  • 14
  • 27
1
<input type ="text" name="email" id="name">

If you dont name the element, its not gona work.

BorisD
  • 1,611
  • 17
  • 22
1
What is your email address?
<input type ="text" email="email">

<br>
What is your phone number?
<input type = "text" phone="phone">

The error here is that the input name should be name and not the field name

What is your email address?
<input type ="text" name="email">

<br>
What is your phone number?
<input type = "text" name="phone">
Anurag Verma
  • 485
  • 2
  • 12