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.
Printable View
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
}
Usually I use.
PHP Code:if (empty($var)) //Define your variable here
{
}
Use Iszaks or use
PHP Code:if( $_POST['variable'] != '' )
{
// posted
}
if($_POST) and if(isset($_POST['submit']) don't work for me... they just refresh the page
isn't
if($_POST) {
// process info
} else {
// error msg
}
and
if(!$_POST) {
// error
} else {
// process data
}
the same?
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.
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>
';
?>