I want to clear something about PHP and HTML (newbie)
-
If you run this in a browser you can see the form. I want to clarify how could that be happen the form is inside the if statement. Is there any way you can hide html code in PHP. The html code will be executed if the "if" statement is true.
<form method="post" action=" . "> <label for="subject">Subject:</label> <input type="text" id="subject" name="subject" value="" /> <label for="message\_body">Say something:</label> <textarea id="message\_body" name="message\_body"></textarea> <input type="submit" id="submit" name="submit" value="Send Email" /> </form>;
-
If you run this in a browser you can see the form. I want to clarify how could that be happen the form is inside the if statement. Is there any way you can hide html code in PHP. The html code will be executed if the "if" statement is true.
<form method="post" action=" . "> <label for="subject">Subject:</label> <input type="text" id="subject" name="subject" value="" /> <label for="message\_body">Say something:</label> <textarea id="message\_body" name="message\_body"></textarea> <input type="submit" id="submit" name="submit" value="Send Email" /> </form>;
First, your 'if' statement is wrong - you have used a single '=', which means it assigns the value
true
to$submit
and then tests it, finding it to be true and executing the block that follows. Here are some options that will work:if($submit == true) {
if($submit === true) {
if($submit) {
The second reason your form will display is that you have set
$submit
totrue
on the second line of the script, and you don't appear to be setting it anything else elsewhere in the code. -
First, your 'if' statement is wrong - you have used a single '=', which means it assigns the value
true
to$submit
and then tests it, finding it to be true and executing the block that follows. Here are some options that will work:if($submit == true) {
if($submit === true) {
if($submit) {
The second reason your form will display is that you have set
$submit
totrue
on the second line of the script, and you don't appear to be setting it anything else elsewhere in the code. -
If you run this in a browser you can see the form. I want to clarify how could that be happen the form is inside the if statement. Is there any way you can hide html code in PHP. The html code will be executed if the "if" statement is true.
<form method="post" action=" . "> <label for="subject">Subject:</label> <input type="text" id="subject" name="subject" value="" /> <label for="message\_body">Say something:</label> <textarea id="message\_body" name="message\_body"></textarea> <input type="submit" id="submit" name="submit" value="Send Email" /> </form>;
flashery wrote:
If you run this in a browser you can see the form.
PHP doesn't run in a browser, it runs in the web server. If you open a PHP file directly in a browser (by File->Open...) instead of loading it from a server the PHP code won't get executed.
-
flashery wrote:
If you run this in a browser you can see the form.
PHP doesn't run in a browser, it runs in the web server. If you open a PHP file directly in a browser (by File->Open...) instead of loading it from a server the PHP code won't get executed.
-
Wow your great. I change the initial value of submit to false. I also change the "if" statement to == but the form still showing. Thanks for your help.
Just to clarify aswell: = is an assignment operator. == is the comparison operator as mentioned above. === is another comparison operator I call identity, which checks for equality AND type. As PHP is not strongly typed, a variable can change types dynamically at runtime. Example:
$a = 2;
$b = "2";A comparison would be like this:
if($a == $b)
{
// Do something.
}..would be TRUE, as they have the same value, but one is an integer and one is a string.
if($a === $b)
{
// This wont happen.
}.. would be FALSE, because they have matching values but different types! For me, understanding this in the beginning helped me to write reliable condition tests for websites and applications.
-
If you run this in a browser you can see the form. I want to clarify how could that be happen the form is inside the if statement. Is there any way you can hide html code in PHP. The html code will be executed if the "if" statement is true.
<form method="post" action=" . "> <label for="subject">Subject:</label> <input type="text" id="subject" name="subject" value="" /> <label for="message\_body">Say something:</label> <textarea id="message\_body" name="message\_body"></textarea> <input type="submit" id="submit" name="submit" value="Send Email" /> </form>;