Jump to content
xisto Community
Sign in to follow this  
Dreamer

Possible To Put An If Statement Inside A Variable?

Recommended Posts

Ok, so I'm using the include() function on my website. Problem is I'm trying to include a search engine form into the layout which is stored in a variable, except the form has an if statement in it and I can't seem to get it working. Here's the code I'm trying to include...CODE <form method=POST action=search.php><p>Search:<br><input type=text name=search size=20 class=textbox size=15 value= <?if (isset($_POST['search'])){ echo $_POST['search']; } ?>><input type=submit value=Submit></form> Just wondering if it is possible for me to put this form with the if statement into a variable, or if there's another way that I could go about doing this. Thanks.

Share this post


Link to post
Share on other sites

try:

<form method=POST action=search.php>[/br]<p>Search:<br>[br]<input type=text name=search size=20 class=textbox size=15 value= [/br]<? if (isset($_POST['search'])){ echo $_POST['search']; } ?>[br]><input type=submit value=Submit>[/br]</form>[br]
or

<form method=POST action=search.php>[/br]<p>Search:<br>[br]<input type=text name=search size=20 class=textbox size=15 value= [/br]<?php if (isset($_POST['search'])){ echo $_POST['search']; } ?>[br]><input type=submit value=Submit>[/br]</form>

Share this post


Link to post
Share on other sites

To increase the "readability" of the code I would do it like :<form method=POST action=search.php><p>Search:<br><?phpecho "<input type=text name=search size=20 class=textbox size=15 value=".$_POST['search'].">";?><input type=submit value=Submit></form>You actually dont have to take the test isset for this. It is only useful for SQL queries that would generate an error if they get blank parameters

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.