Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Possible To Put An If Statement Inside A Variable?
Dreamer
post Oct 24 2004, 11:08 AM
Post #1


Newbie [Level 1]
*

Group: Members
Posts: 24
Joined: 24-October 04
Member No.: 1,919



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.
Go to the top of the page
 
+Quote Post
LuciferStar
post Oct 27 2004, 08:14 AM
Post #2


Advanced Member
*******

Group: Members
Posts: 114
Joined: 9-August 04
From: Suzhou Jiangsu China
Member No.: 743



try:
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>

or
CODE
<form method=POST action=search.php>
<p>Search:<br>
<input type=text name=search size=20 class=textbox size=15 value=
<?php if (isset($_POST['search'])){ echo $_POST['search']; } ?>
><input type=submit value=Submit>
</form>
Go to the top of the page
 
+Quote Post
king mike
post Nov 6 2004, 10:39 AM
Post #3


Newbie [Level 1]
*

Group: Members
Posts: 12
Joined: 6-November 04
Member No.: 2,152



To increase the "readability" of the code I would do it like :

<form method=POST action=search.php>
<p>Search:<br>
<?php
echo "<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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Stored Or Global Variable?(1)
  2. Php Parse Error(2)
  3. Calling A False Variable...(6)
  4. Determining Whether A Phrase Is In A Variable(2)
  5. Globals Inside Functions(4)
  6. <textarea> Tag Is Not Accepting Php Variable(2)
  7. Complex Php Echo Statement Assistance(3)
  8. Converting Characters In A Variable To Individual Values In An Array(2)
  9. Php Form Help!(3)
  10. What Is Wrong With This Php-sql Select Where Statement?(5)
  11. Getting An Array Value Of A Dynamic Variable(9)
  12. Script Help Required: Undefined Variable(3)
  13. Unexpected T_variable...(3)


 



- Lo-Fi Version Time is now: 8th October 2008 - 03:49 AM