What's the proper way to check to see if POST data was submitted?
if($_POST) doesnt work and if($_POST['submit']) doesnt work if I had a submit button named submit.

That works for me also.PHP Code:if ($_POST)
{
// Post submited
}
But I usually do..PHP Code:if (empty($_POST) === false)
{
// Post submited
}
So yeah, look into empty and isset functions.PHP Code:if (isset($_POST['submit']))
{
// Post submited
}
Last edited by Iszak; 28-02-2009 at 02:08 AM.
Usually I use.
PHP Code:if (empty($var)) //Define your variable here
{
}
Back for a while.
Use Iszaks or use
PHP Code:if( $_POST['variable'] != '' )
{
// posted
}
Yeah, just in reverse order. But what I was saying is if you're wanting to check if data is empty, use either the empty function or !$_POST['lol']. You need to make sure they're submitting the form by doing something like:
That will check if they have posted the form. On the submit name just add 'form'.PHP Code:if(isset($_POST['form']))
{
}
This isn't the best method but it'll work.
Edit: Oh and add the method as POST.
Last edited by Excellent2; 28-02-2009 at 11:33 PM.
Back for a while.
Same problem. Page just refreshes.
For example:
same with issetPHP Code:<?php
if(!$_POST) {
echo "hi $_POST['name']";
} else {
echo '
<form method="post" enctype="text/plain">
Name: <input type="text" name="name"> <br />
<input type="submit" value="Submit" name="submit">
</form>
';
?>PHP Code:<?php
if($_POST) {
echo "hi $_POST['name']";
} else {
echo '
<form method="post" enctype="text/plain">
Name: <input type="text" name="name"> <br />
<input type="submit" value="Submit" name="submit">
</form>
';
?>
Want to hide these adverts? Register an account for free!