Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Peh Hui Shi
4,751 Points$_POST is empty
I tried to read from $_POST using php code: var_dump($_POST);
But the result is array(0) { }
Anything I need to set?
6 Answers

Fabion Stephens
Courses Plus Student 5,893 PointsYou have a typo for the form 'method' attribute. Maybe thats the issue. Let me know.

Joey L.
4,601 PointsThis means that the $_POST array did not receive any variables when the form was sent. Did you give name attributes to each for input element? These are the keys which are created within $_POST. Also ensure you're checking $_POST in the corresponding file to where the form's action attribute points to

Peh Hui Shi
4,751 PointsIn my contact.php
<form mehod="post" action="contact-process.php">
<table>
<tr>
<th><label for="name">Name</label></th>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<th><label for="email">Email</label></th>
<td><input type="text" name="email" id="email"></td>
</tr>
<tr>
<th><label for="message">Message</label></th>
<td><textarea name="message" id="message"></textarea></td>
</tr>
</table>
<input type="submit" value="Send">
</form>
In my contact-process.php
<?php
var_dump($_POST);
?>
URL after I clicked the Send Button
http://localhost/shirts4mike/contact-process.php?name=Mike&email=mike%40gmail.com&message=hi

Mohamed Nabih
11,416 PointsI'm still getting empty array
contact.php
<form method="post" action="contact-process.php">
<table>
<tr>
<th>
<label for"name">Name</label>
</th>
<td>
<input type="text" name"name" id="name">
</td>
</tr>
<tr>
<th>
<label for"email">Email</label>
</th>
<td>
<input type="text" name"email" id="email">
</td>
</tr>
<tr>
<th>
<label for"message">Message</label>
</th>
<td>
<textarea name"message" id="message"></textarea>
</td>
</tr>
</table>
<input type="submit" value="Send">
</form>
contact-process.php
<?php
var_dump($_POST);
?>

Joey L.
4,601 PointsYour for and name attributes are missing an equals sign. There is no key being registered in the $_POST array as a result.

Mohamed Nabih
11,416 PointsThanks buddy :)

rabi mughal
Courses Plus Student 1,863 Points<form mehod="post" action="contact-process.php">
<table>
<tr>
<th><label for="name">Name</label></th>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<th><label for="email">Email</label></th>
<td><input type="text" name="email" id="email"></td>
</tr>
<tr>
<th><label for="message">Message</label></th>
<td><textarea name="message" id="message"></textarea></td>
</tr>
</table>
<input type="submit" value="Send">
</form>

rabi mughal
Courses Plus Student 1,863 Pointswhats wrong in my code i am getting empty array :(
Peh Hui Shi
4,751 PointsPeh Hui Shi
4,751 PointsThank you
Fabion Stephens
Courses Plus Student 5,893 PointsFabion Stephens
Courses Plus Student 5,893 PointsYou are welcome :) Happy coding!