Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. I want to clear something about PHP and HTML (newbie)

I want to clear something about PHP and HTML (newbie)

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phphtml
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    flashery
    wrote on last edited by
    #1

    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>;
    
    G M N 3 Replies Last reply
    0
    • F flashery

      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>;
      
      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      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 to true on the second line of the script, and you don't appear to be setting it anything else elsewhere in the code.

      F 1 Reply Last reply
      0
      • G Graham Breach

        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 to true on the second line of the script, and you don't appear to be setting it anything else elsewhere in the code.

        F Offline
        F Offline
        flashery
        wrote on last edited by
        #3

        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.

        J 1 Reply Last reply
        0
        • F flashery

          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>;
          
          M Offline
          M Offline
          markkuk
          wrote on last edited by
          #4

          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.

          F 1 Reply Last reply
          0
          • M markkuk

            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.

            F Offline
            F Offline
            flashery
            wrote on last edited by
            #5

            I run this stuff using my local web server xampp in localhost.

            1 Reply Last reply
            0
            • F flashery

              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.

              J Offline
              J Offline
              Jon Heather
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • F flashery

                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>;
                
                N Offline
                N Offline
                Necron8
                wrote on last edited by
                #7

                I think you might have a syntax error. if you have to check something, then the if statement should be: if($submit == true) if($submit = true) -> is setting submit to true not checking. Hope this helps.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups