spooke2k Posted June 23, 2007 Share Posted June 23, 2007 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 23, 2007 Share Posted June 23, 2007 Not really sure what you are asking. Your question is not very clear and your code is not much clearer either. If you could rephase your question along with some visual examples. Then I may be able to help you Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 23, 2007 Share Posted June 23, 2007 Use a switch in a switch and don't use that <> "" or <> 0 use ISSET() or !ISSET() Quote Link to comment Share on other sites More sharing options...
spooke2k Posted June 23, 2007 Author Share Posted June 23, 2007 all im trying to do is find all the different combinations of issets out of the 3 items on the form and display a statement saying what has been selected. sorry for confussion Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 23, 2007 Share Posted June 23, 2007 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> Quote Link to comment Share on other sites More sharing options...
spooke2k Posted June 23, 2007 Author Share Posted June 23, 2007 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 24, 2007 Share Posted June 24, 2007 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.