Jump to content

[SOLVED] if statement


spooke2k

Recommended Posts

i have 3 form objects that i wish to check against.  i basically want to echo the ojects selected.

 

So i i have date1 spent and product with data in them i want to echo date product and spent and same with all others nut if the post date is only set and nothing else is then echo date and same if more than one object is set i want to say what objects they are but code isnt working very well and seems a reaLLY long way round to do it is there a easier way and code belopw isnt working proberly so any help much appeciated 

 

if($_POST['date1'] <> "")
{
    if($_POST['Spent'] <> 0) 
        {
            if($_POST['product'] <> 0)
                {
                echo "<br>Date Spent Prod</br>"; 
                  }else{ 
                echo "<br>Date spend</br>";
                }
        
        }else { echo "<br>date</br>";
        } 

}elseif($_POST['Spent'] <> 0){ 
           if($_POST['date1'] <> "")
	   {
            if($_POST['product'] <> 0)
                {
             echo "<br>Date Spent Prod</br>";
                }else{ 
               echo "<br>Date Spent</br>";
                }
        }else { echo"<br>spent</br>";
        }
        
}elseif($_POST['product'] <> 0){
           if($_POST['date1'] <> ""){
            if($_POST['Spend'] <> 0) 
                {
              echo "<br>Date Spent Prod</br>";
                }else{ 
                  echo "<br>Date Prod</br>";
                }
        }else { echo "<br>prod</br>";
}
} 
?>

 

spooke2k

Link to comment
https://forums.phpfreaks.com/topic/56856-solved-if-statement/
Share on other sites

Is this what you mean:

<?php

if(isset($_POST['submit']))
{
    if(isset($_POST['date']) && !empty($_POST['date']))
    {
        echo 'Date is set: - ' . $_POST['date'] . '<br />';
    }
    else
    {
        echo 'Date is not set!<br />';
    }

    if(isset($_POST['spent']) && !empty($_POST['spent']))
    {
        echo 'Spent is set: - ' . $_POST['spent'] . '<br />';
    }
    else
    {
        echo 'Spent is not set!<br />';
    }

    if(isset($_POST['product']) && !empty($_POST['product']))
    {
        echo 'Product is set - ' . $_POST['product'] . '<br />';
    }
    else
    {
        echo 'Product is not set!<br />';
    }

    echo '<hr />';
}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  Date: <input type="text" name="date" /><br />
  Spent: <input type="text" name="spent" /><br />
  Product: <input type="text" name="product" /><br />
  <input type="submit" name="submit" />
</form>

Link to comment
https://forums.phpfreaks.com/topic/56856-solved-if-statement/#findComment-281011
Share on other sites

yes except that if more than one is set like date and product are  i need to show that they are both set for all combinations so date + prod + spent  echo all are set or just spent and prod etc.  You can see why i mean by not sure if im doing it right way

 

 

reason is iif they have set more than one piece of criteria i need to show this

spooke2k

Link to comment
https://forums.phpfreaks.com/topic/56856-solved-if-statement/#findComment-281055
Share on other sites

OK jsut remove the else statements:

<?php

if(isset($_POST['submit']))
{
    if(isset($_POST['date']) && !empty($_POST['date']))
    {
        echo 'Date is set: - ' . $_POST['date'] . '<br />';
    }

    if(isset($_POST['spent']) && !empty($_POST['spent']))
    {
        echo 'Spent is set: - ' . $_POST['spent'] . '<br />';
    }

    if(isset($_POST['product']) && !empty($_POST['product']))
    {
        echo 'Product is set - ' . $_POST['product'] . '<br />';
    }

    echo '<hr />';
}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  Date: <input type="text" name="date" /><br />
  Spent: <input type="text" name="spent" /><br />
  Product: <input type="text" name="product" /><br />
  <input type="submit" name="submit" />
</form>

Link to comment
https://forums.phpfreaks.com/topic/56856-solved-if-statement/#findComment-281237
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.