Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$_POST is empty after form submission [closed]

Tags:

html

post

forms

php

I set up this test page up on my server. Please tell me why the $_POST array does not contain anything even when I submit the form. I have tried this in three different browsers and nothing happens.

<?php print_r($_POST);?>

<form method="post">

<p><label>Email: </label>
<input type="text" id="login_email" />
</p>

<p><label>Password: </label>
<input type="password" id="login_password" />
</p>

<p><label>Remember Me?: </label>
<input type="checkbox" id="login_remember" />
</p>

<p>
<input type="submit" value="Login" />
</p>

</form>

I have been writing PHP for years and this has never happened before. What is wrong with this code?

like image 939
Mike Stanford Avatar asked May 12 '09 18:05

Mike Stanford


2 Answers

Your input elements do not have name attributes. Should be:

<input type="text" id="login_email" name="login_email" />

If an input element does not have a name attribute, it is not sent as part of the POST data.

like image 60
Ayman Hourieh Avatar answered Sep 19 '22 17:09

Ayman Hourieh


Well, you don't have an action for the form tag? It should be the script name:

<form method="post" action="scriptname.php">

...and you're also not setting the names for each form input - the browser doesn't submit the ID as the element name.

like image 32
BrynJ Avatar answered Sep 20 '22 17:09

BrynJ