Forums

PHP

This topic is locked

if statemate

Posted 06 Dec 2001 23:48:24
1
has voted
06 Dec 2001 23:48:24 Keith Slater posted:
Hey I got a question about some PHP code. I was wondering how to do something. I have a form field and Im wanting to set up an if statement so if they dont enter something it will echo something and if they do enter something it will enter something. I know this is probbaly simple but Im just drawing a blank here. Thanks a lot



Keith Slater

Replies

Replied 07 Dec 2001 11:40:06
07 Dec 2001 11:40:06 Tim Green replied:
<pre id=code><font face=courier size=2 id=code>
if ($HTTP_POST_VARS["FormFieldName"] !="" {
echo "Field has a value";
} else {
echo "Field is blank";
}
</font id=code></pre id=code>
Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>

Edited by - rawveg on 07 Dec 2001 11:41:15
Replied 07 Dec 2001 15:37:23
07 Dec 2001 15:37:23 Keith Slater replied:
Ah well that was easy enough heheh.
Well now Im trying to take that and put it inside quotes. its like this:

$message = "
if ($HTTP_POST_VARS["FormFieldName !="" { echo "Field has a value";} else { echo "Field is blank";}
";

Ive been messing with it with putting periods in different places but I cant figure out how to make that work

Thanks a lot

Keith Slater
Replied 08 Dec 2001 01:25:44
08 Dec 2001 01:25:44 Tim Green replied:
If you are wishing to echo that line of code precede all instances of " within the string with a
It should also be noted that for some reason this form removes the " and ] from the code. You should ensure that the FormFieldName has these immediately after....

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 08 Dec 2001 05:35:07
08 Dec 2001 05:35:07 Keith Slater replied:
I think the forum took out the character you were trying to type... What it \? If it was then I tried that already and it didnt work. When I did that it actually the PHP and didnt run anything. It just displayed the PHP lines...

Thanks again


Keith Slater
Replied 08 Dec 2001 21:39:24
08 Dec 2001 21:39:24 Tim Green replied:
OK, I misunderstood your intent.

The forum is removing " and a close square bracket that should come after FormFieldName...

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 10 Dec 2001 15:40:32
10 Dec 2001 15:40:32 Keith Slater replied:
Heh now Im really confused. I see what your talking about that the forum removes the ]. Let me give you a different example of what Im trying to do:

$price = "if ($level == "standard"
{ echo $standard }
if ($level == "advanced"
{ echo $advanced }
if ($level == "premiere"
{ echo $premiere }
if ($level == "enterprise"
{ echo $enterprise }
if ($level == "ecommerce"
{ echo $ecom }";

I want to put that if statement inside a string, but of course if gives me a parse error.

Thanks again

Keith Slater
Replied 13 Dec 2001 10:42:21
13 Dec 2001 10:42:21 Tim Green replied:
Eeeek! You really are trying to confuse the PHP parser!

Try:-

$price = "if ($level == 'standard')\n";
$price .= "{ echo $standard }\n";
$price .= "if ($level == 'advanced')\n";
$price .= "{ echo $advanced }\n";
$price .= "if ($level == 'premiere')\n";
$price .= "{ echo $premiere }\n";
$price .= "if ($level == 'enterprise')\n";
$price .= "{ echo $enterprise }\n";
$price .= "if ($level == 'ecommerce')\n";
$price .= "{ echo $ecom }";

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>

Reply to this topic