1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php not working?

Discussion in 'PHP' started by Matt Ridge, Sep 26, 2011.

  1. #1
    I have some php code in my page, to verify that something is entered into the page before allowing it to be accepted. Yet when said field is not filled and I press submit, it goes through without notifying me.
    SEMrush
    Here is the code:

    
    <!DOCTYPE html 
         PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>PDI Non-Conforming Materials Report</title>
    <link rel="stylesheet" type="text/css" href="pdi.css" />
    </head>
    <body>
    
    
    <div id="logo">
        <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" />
    </div>
    <?php
    
    
    if (empty($Added_By)){
    //Field is empty.
            echo 'You forgot to add who filed the initial report in the Added By field ';
        }
    if (!empty($Added_By)){
    //Final code to make sure all fields are entered.
    }
    ?>    
    <div id="title">    
        <h2>Non-Conforming Materials Report (NCMR)</h2>
    </div>
    
    
    <form id="all" action ="database.php" method="echo">
        <fieldset>
            <div id ="added">    
                <label>Added By:</label>
                <input type="text" name="Added_By" value="" />
                <label>on:</label>
                <input type="text" name="Added_By_Date" value="" />
            </div>    
            
        <div id="box">    
            <div id ="part">
                <label>Nexx Part:</label>
                <input type="text" name="Nexx_Part" value="" /><br />
                <label>Nexx Rev:</label>
                <input type="text" name="Nexx_Rev" value="" /><br />
                <label>Nexx Part Description:</label>
                <textarea name="Nexx_Part_Description" rows="4" cols="16"></textarea><br />
                <label>NCMR Qty:</label>
                <input type="text" name="NCMR_Qty" value="" />
                <div id ="jo">
                <br />
                    <label>JO:</label><br />
                    <input type="text" name="JO" size="3" value="" />
                </div>    
                <div id ="sn">
                <br />
                    <label>SN:</label><br />
                    <input type="text" name="SN" size="3" value="" />
                </div>    
                <div id ="inv">
                <br />
                    <label>INV:</label>
                    <br />
                    <input type="text" name="INV" size="3" value="" />
                </div>    
            </div>
            
            <div id ="manu">
                <label>Nexx Inventory On Hand:</label>
                <input type="text" name="Nexx_Inventory_On_Hand" value="" /><br />
                <label>Nexx Inventory Chk:</label>
                <input type="text" name="Nexx_Inventory_Chk" value="" /><br />
                <label>Supplier Name:</label>
                <textarea name="Supplier_Name" rows="4" cols="16"></textarea><br />
                <label>Supplier Number:</label>
                <input type="text" name="Supplier_Number" value="" /><br />
                <label>Manufacturer Part Number:</label>
                <input type="text" name="Manufacturer_Part_Number" value="" /><br />
                <label>Manufacturer Serial Number: </label>
                <input type="text" name="Manufacturer_Serial_Number" value="" />
                <br />
                <label>NCMR ID:</label>
                <input type="text" name="NCMR_ID" value="" />
            </div>
        </div>
    
    
        <div id="box2">
                <label>Nonconformity: (Be Specific)</label><br />
                <textarea name="Nonconformity" rows="3" cols="85" ></textarea><br />
                <label>Disposition: (Initiator)</label><br />
                <textarea name="Disposition" rows="3" cols="85" ></textarea><br />
                <label>Comments:</label><br />
                <textarea name="Comments" rows="3" cols="85" ></textarea><br />
                <label>Comments and Additional Details:</label><br />
                <textarea name="CommentsAdditional_Details " rows="3" cols="85" ></textarea><br />
                <div id ="po">
                <br />
                    <label>PO:</label><br />
                    <input type="text" name="PO" size="7" value="" />
                </div>    
                <div id ="pod">
                <br />
                    <label>PO Date:</label><br />
                    <input type="text" name="PO_Date" size="7" value="" />
                </div>    
                <div id ="dr">
                <br />
                    <label>Date Recieved:</label><br />
                    <input type="text" name="Date_Recieved" size="7" value="" />
                </div>    
        </div>
                <div id="button">
                <input type="submit" value="Submit NCMR" name="submit" />
                </div>
        </fieldset>
        
    <div id="xhtml">
        <a href="http://validator.w3.org/check?uri=referer"><img
          src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
      </div>    
    </form>
    </body>
    </html>
    
    Code (markup):
     
    Solved! View solution.
    Matt Ridge, Sep 26, 2011 IP
    SEMrush
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    You need to remember that php works on the server on which the files are hosted and not through a users browser.

    Your code does work, but you should be looking at javascript and add a onclick function to your submit button.
     
    Last edited: Sep 26, 2011
    MyVodaFone, Sep 26, 2011 IP
  3. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #3
    But I want the code to not allow me to continue if the field for Added_By is not fulfilled, and come back with an error.

    At this point in time it doesn't... so no the code doesn't work as far as I can tell.
     
    Matt Ridge, Sep 26, 2011 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    If you where to load the script above into a test file, you will see on the second line:
    You forgot to add who filed the initial report in the Added By field
    Code (markup):
    ..because $Added_By is nothing it contains no information. Therefore you get the message echoed out.

    Anyway as above you need to look at using javascript or something more complex like ajax

    Although a simple code through javascript would do just a well.

    Test the following if you care to:
    
    <!DOCTYPE html 
         PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>PDI Non-Conforming Materials Report</title>
    <link rel="stylesheet" type="text/css" href="pdi.css" />
    </head>
    <body>
    
    
    <div id="logo">
        <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" />
    </div>
    
    <script type="text/javascript">
    function validateForm()
    {
    var x=document.forms["all"]["Added_By"].value;
    if (x==null || x=="")
      {
      alert("You forgot to add who filed the initial report in the Added By field");
      return false;
      }
    }
    </script>
        
    <div id="title">    
        <h2>Non-Conforming Materials Report (NCMR)</h2>
    </div>
    
    
    <form id="all" name="all" action ="database.php" method="post" onsubmit="return validateForm()">
        <fieldset>
            <div id ="added">    
                <label>Added By:</label>
                <input type="text" name="Added_By" value="" />
                <label>on:</label>
                <input type="text" name="Added_By_Date" value="" />
            </div>    
            
        <div id="box">    
            <div id ="part">
                <label>Nexx Part:</label>
                <input type="text" name="Nexx_Part" value="" /><br />
                <label>Nexx Rev:</label>
                <input type="text" name="Nexx_Rev" value="" /><br />
                <label>Nexx Part Description:</label>
                <textarea name="Nexx_Part_Description" rows="4" cols="16"></textarea><br />
                <label>NCMR Qty:</label>
                <input type="text" name="NCMR_Qty" value="" />
                <div id ="jo">
                <br />
                    <label>JO:</label><br />
                    <input type="text" name="JO" size="3" value="" />
                </div>    
                <div id ="sn">
                <br />
                    <label>SN:</label><br />
                    <input type="text" name="SN" size="3" value="" />
                </div>    
                <div id ="inv">
                <br />
                    <label>INV:</label>
                    <br />
                    <input type="text" name="INV" size="3" value="" />
                </div>    
            </div>
            
            <div id ="manu">
                <label>Nexx Inventory On Hand:</label>
                <input type="text" name="Nexx_Inventory_On_Hand" value="" /><br />
                <label>Nexx Inventory Chk:</label>
                <input type="text" name="Nexx_Inventory_Chk" value="" /><br />
                <label>Supplier Name:</label>
                <textarea name="Supplier_Name" rows="4" cols="16"></textarea><br />
                <label>Supplier Number:</label>
                <input type="text" name="Supplier_Number" value="" /><br />
                <label>Manufacturer Part Number:</label>
                <input type="text" name="Manufacturer_Part_Number" value="" /><br />
                <label>Manufacturer Serial Number: </label>
                <input type="text" name="Manufacturer_Serial_Number" value="" />
                <br />
                <label>NCMR ID:</label>
                <input type="text" name="NCMR_ID" value="" />
            </div>
        </div>
    
    
        <div id="box2">
                <label>Nonconformity: (Be Specific)</label><br />
                <textarea name="Nonconformity" rows="3" cols="85" ></textarea><br />
                <label>Disposition: (Initiator)</label><br />
                <textarea name="Disposition" rows="3" cols="85" ></textarea><br />
                <label>Comments:</label><br />
                <textarea name="Comments" rows="3" cols="85" ></textarea><br />
                <label>Comments and Additional Details:</label><br />
                <textarea name="CommentsAdditional_Details " rows="3" cols="85" ></textarea><br />
                <div id ="po">
                <br />
                    <label>PO:</label><br />
                    <input type="text" name="PO" size="7" value="" />
                </div>    
                <div id ="pod">
                <br />
                    <label>PO Date:</label><br />
                    <input type="text" name="PO_Date" size="7" value="" />
                </div>    
                <div id ="dr">
                <br />
                    <label>Date Recieved:</label><br />
                    <input type="text" name="Date_Recieved" size="7" value="" />
                </div>    
        </div>
                <div id="button">
                <input type="submit" value="Submit NCMR" name="submit" />
                </div>
        </fieldset>
        
    <div id="xhtml">
        <a href="http://validator.w3.org/check?uri=referer"><img
          src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
      </div>    
    </form>
    </body>
    </html>
    
    
    Code (markup):
     
    Last edited: Sep 26, 2011
    MyVodaFone, Sep 26, 2011 IP
  5. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Sorry, but Java, or JavaScript is not possible for this application.

    It has too many oppertunities to be hacked. I am looking for a way with the script I have. Please stop pushing java as a cure all. It isn't going to be used in this project. If I was going to do anything of the sort, I'd use HTML 5, not java anyway.

    As for the rest, can you suggest a way that uses only XHTML and PHP instead?
     
    Matt Ridge, Sep 26, 2011 IP
  6. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,562
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #6
    Matt's right, JavaScript is not how you should be doing this, since its not degradable. If you did have a Javascript form validation, it would also have to have PHP as a fallback.As for your problem, you should submit the form to the same page as itself and then check from there. However it's hard to tell with just that file, because it doesn't seem that $Added_By has been set.
    $Added_By = $_POST['Added_By'];
    PHP:
    will get the value of the form on submit. Then just do the empty check as you are.
     
    blueparukia, Sep 26, 2011 IP
  7. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #7
    Matt, this is the free section on DP if you don't like free efforts use the programming section and pay someone fix your code.

    Anyway try the following php solution:
    
    <?php
    
        if(isset($_POST['Added_By'])){
    
    if (empty($_POST['Added_By'])) {
        echo "You forgot to add who filed the initial report in the Added By field";
    }else{ 
    header('Location: database.php');
    }
    
        }
    
    ?>
    <!DOCTYPE html 
         PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>PDI Non-Conforming Materials Report</title>
    <link rel="stylesheet" type="text/css" href="pdi.css" />
    </head>
    <body>
    
    
    <div id="logo">
        <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" />
    </div>
    
    <div id="title">    
        <h2>Non-Conforming Materials Report (NCMR)</h2>
    </div>
    
    
    <form id="all" name="all" action ="" method="post">
        <fieldset>
            <div id ="added">    
                <label>Added By:</label>
                <input type="text" name="Added_By" value="" />
                <label>on:</label>
                <input type="text" name="Added_By_Date" value="" />
            </div>    
            
        <div id="box">    
            <div id ="part">
                <label>Nexx Part:</label>
                <input type="text" name="Nexx_Part" value="" /><br />
                <label>Nexx Rev:</label>
                <input type="text" name="Nexx_Rev" value="" /><br />
                <label>Nexx Part Description:</label>
                <textarea name="Nexx_Part_Description" rows="4" cols="16"></textarea><br />
                <label>NCMR Qty:</label>
                <input type="text" name="NCMR_Qty" value="" />
                <div id ="jo">
                <br />
                    <label>JO:</label><br />
                    <input type="text" name="JO" size="3" value="" />
                </div>    
                <div id ="sn">
                <br />
                    <label>SN:</label><br />
                    <input type="text" name="SN" size="3" value="" />
                </div>    
                <div id ="inv">
                <br />
                    <label>INV:</label>
                    <br />
                    <input type="text" name="INV" size="3" value="" />
                </div>    
            </div>
            
            <div id ="manu">
                <label>Nexx Inventory On Hand:</label>
                <input type="text" name="Nexx_Inventory_On_Hand" value="" /><br />
                <label>Nexx Inventory Chk:</label>
                <input type="text" name="Nexx_Inventory_Chk" value="" /><br />
                <label>Supplier Name:</label>
                <textarea name="Supplier_Name" rows="4" cols="16"></textarea><br />
                <label>Supplier Number:</label>
                <input type="text" name="Supplier_Number" value="" /><br />
                <label>Manufacturer Part Number:</label>
                <input type="text" name="Manufacturer_Part_Number" value="" /><br />
                <label>Manufacturer Serial Number: </label>
                <input type="text" name="Manufacturer_Serial_Number" value="" />
                <br />
                <label>NCMR ID:</label>
                <input type="text" name="NCMR_ID" value="" />
            </div>
        </div>
    
    
        <div id="box2">
                <label>Nonconformity: (Be Specific)</label><br />
                <textarea name="Nonconformity" rows="3" cols="85" ></textarea><br />
                <label>Disposition: (Initiator)</label><br />
                <textarea name="Disposition" rows="3" cols="85" ></textarea><br />
                <label>Comments:</label><br />
                <textarea name="Comments" rows="3" cols="85" ></textarea><br />
                <label>Comments and Additional Details:</label><br />
                <textarea name="CommentsAdditional_Details " rows="3" cols="85" ></textarea><br />
                <div id ="po">
                <br />
                    <label>PO:</label><br />
                    <input type="text" name="PO" size="7" value="" />
                </div>    
                <div id ="pod">
                <br />
                    <label>PO Date:</label><br />
                    <input type="text" name="PO_Date" size="7" value="" />
                </div>    
                <div id ="dr">
                <br />
                    <label>Date Recieved:</label><br />
                    <input type="text" name="Date_Recieved" size="7" value="" />
                </div>    
        </div>
                <div id="button">
                <input type="submit" value="Submit NCMR" name="submit" />
                </div>
        </fieldset>
        
    <div id="xhtml">
        <a href="http://validator.w3.org/check?uri=referer"><img
          src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
      </div>    
    </form>
    </body>
    </html>
    
    
    PHP:
    It will check to see if Added_By has a value, if it doesn't it will echo your message or else redirect to database.php, but like @blueparukia's suggests, it would be best if the file contents of database.php was on this page, if you do that:

    replace:
    header('Location: database.php');
    Code (markup):
    ....with your code from database.php
     
    Last edited: Sep 27, 2011
    MyVodaFone, Sep 27, 2011 IP
  8. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #8
    Actually you should use Javascript (which has nothing to do with Java). If the user has Javascript turned off, he'll submit the form and get a message back. If it's turned on, the form won't submit - it'll tell him to fill in the blank. (You'll have to reload the form with all the already-entered data in it. I detest having a form go blank because I left out one box, and I think most people do.)

    The Javascript in this case can't be hacked - all it does is check the length of the text input and, if it's 0 (or less than your minimum), alerts and returns false. Not much to hack there. (The Javascript interpreter is in the browser - you're just adding a few lines of innocuous script.)

    If you don't want Javascript, you also don't get AJAX, so no nice popups without reloading the entire page - very 1990ish.
     
    Rukbat, Sep 27, 2011 IP
  9. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #9
    I asked for the PHP/SQL solution because of my limitations, and also personal preferences... also because the job also is security sensitive, I can't use something that allows a greater ease of hacking potential...

    That being said, thanks for the response.

    Here is the database php script;

    I just attempted this post, and it doesn't work.

    http://www.kaboomlabs.com/PDI/ncmr.html

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    
    
    
    
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>PDI Non-Conforming Materials Report </title>
    </head>
    
    
    
    
    <body>
      <h2>PDI Non-Conforming Materials Report</h2>
    
    
    
    
    <?php
      $Added_By = $_POST['Added_By'];
      $Added_By_Date = date('Y-m-d',strtotime($_POST['Added_By_Date']));
      $Nexx_Part = $_POST['Nexx_Part'];
      $Nexx_Rev = $_POST['Nexx_Rev'];
      $Nexx_Part_Description = $_POST['Nexx_Part_Description'];
      $NCMR_Qty = $_POST['NCMR_Qty'];
      $JO = $_POST['JO'];
      $SN = $_POST['SN'];
      $INV = $_POST['INV'];
      $Nexx_Inventory_On_Hand = $_POST['Nexx_Inventory_On_Hand'];
      $Nexx_Inventory_Chk = $_POST['Nexx_Inventory_Chk'];
      $Supplier_Name = $_POST['Supplier_Name'];
      $Supplier_Number = $_POST['Supplier_Number'];
      $Manufacturer_Part_Number = $_POST['Manufacturer_Part_Number'];
      $Manufacturer_Serial_Number = $_POST['Manufacturer_Serial_Number'];
      $NCMR_ID = $_POST['NCMR_ID'];
      $Nonconformity = $_POST['Nonconformity'];
      $Disposition = $_POST['Disposition'];
      $Comments = $_POST['Comments'];
      $CommentsAdditional_Details = $_POST['CommentsAdditional_Details'];
      $PO = $_POST['PO'];
      $PO_Date = date('Y-m-d',strtotime($_POST['PO_Date']));
      $Date_Received = date('Y-m-d',strtotime($_POST['Date_Received']));
    
    
    
    
      $dbc = mysqli_connect('localhost', 'pawz_PDI', 'pdi1234', 'pawz_PDI')
        or die('Error connecting to MySQL server.');
    
    
    
    
      $query= "INSERT INTO ncmrtest (Added_By, Added_By_Date, Nexx_Part, Nexx_Rev, Nexx_Part_Description, NCMR_Qty, JO, SN, INV, Nexx_Inventory_On_Hand, Nexx_Inventory_Chk, Supplier_Name, Supplier_Number, Manufacturer_Part_Number, Manufacturer_Serial_Number, NCMR_ID, Nonconformity, Disposition, Comments, CommentsAdditional_Details, PO, PO_Date, Date_Received) 
      
      values('$Added_By', '$Added_By_Date', '$Nexx_Part', '$Nexx_Rev', '$Nexx_Part_Description', '$NCMR_Qty', '$JO', '$SN', '$INV', '$Nexx_Inventory_On_Hand', '$Nexx_Inventory_Chk', '$Supplier_Name', '$Supplier_Number', '$Manufacturer_Part_Number', '$Manufacturer_Serial_Number', '$NCMR_ID', '$Nonconformity', '$Disposition', '$Comments', '$CommentsAdditional_Details', '$PO', '$PO_Date', '$Date_Received')"; 
    
    
      if (!$result = mysqli_query($dbc, $query)) 
      {
      printf("Error message: %s\n", mysqli_error($dbc));
    }
    
    
    
    
      mysqli_close($dbc);
    
    
    
    
      echo '<p>Thanks for submitting the form. The information has been entered and will be reviewed by the correct personnel.</p>';
      ?>
    
    
    
    
    </body>
    </html>
    
    Code (markup):
     
    Last edited: Sep 27, 2011
    Matt Ridge, Sep 27, 2011 IP
  10. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #10
    Unless you looked at the form being entered, there is no reason for pop-ups, etc this is an internal form, I am only publishing a version of it outside for now to show a demo for help... that being said, a form going blank? All you need to do is hit the back button and the data is still there.

    http://www.kaboomlabs.com/PDI/ncmr.html
     
    Matt Ridge, Sep 27, 2011 IP
  11. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #11
    In your database php (or whatever you call it), use empty function to check for empty variables. If you found one, just redirect back to the form page with a proper error message.
     
    fairuz.ismail, Sep 27, 2011 IP
  12. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #12
    That is what I am trying to do, I am asking how to do it. It seems people insist on using java, which I am not able to do... so if you could help it be greatly appreciated.
     
    Last edited: Sep 27, 2011
    Matt Ridge, Sep 27, 2011 IP
  13. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #13
    That is what I am trying to do, I am asking how to do it. It seems people insist on using java, which I am not able to do... so if you could help it be greatly appreciated.
     
    Matt Ridge, Sep 27, 2011 IP
  14. #14
    OK, from what I can tell each of your pages is a HTML file with PHP. This is a far from optimal way to do it, you should be implementing a template system.

    It's also much simpler if the form submits to its own file rather than an external file, that saves it from redirecting and having to pass values as cookies or in GET.

    Finally your form method was echo, which is not a valid method and wouldn't have been read by $_POST.

    Attached is a completed one-file solution that could do with refinement and tidying, but is functional and should be secure. There's much I would do to improve on this but it'll give you a general idea.

    Download: View attachment form.php
     
    blueparukia, Sep 27, 2011 IP
    Matt Ridge likes this.
  15. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #15
    Thanks, but amuse me here, I thought best practices was not to have the <?php and <? encompassing XHTML?
     
    Matt Ridge, Sep 27, 2011 IP
  16. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,562
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #16
    Every time you open an <?php, the PHP processor starts and then stops at the ?>. Doing this many times during the course of a document can slow performance - though granted most likely not significantly - due to continuous stop/starting of the PHP.

    Ideally, you should only ever have one <?php and ?> per file.

    It's the same with enclosing variables in single quotes as opposed to double quotes, just marginal performance increase.
     
    blueparukia, Sep 27, 2011 IP
  17. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #17
    Ok, that makes sense, but how much of a lag are we talking? milliseconds?
     
    Matt Ridge, Sep 27, 2011 IP
  18. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,562
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #18
    Miniscule amounts of time no one will notice in any but the most intensive of applications.

    It's a good idea to get into the habit of designing a program to be the absolute most efficient it can be though, so if you ever get contracted to write something that gets as big as Facebook you won't have to rewrite tens of millions of lines of code.
    I always try to do everything I can to minimize server load and increase human readability.
     
    blueparukia, Sep 27, 2011 IP
  19. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #19
    The only reason I am asking is because I am attempting to write strict code... that's all.
     
    Matt Ridge, Sep 27, 2011 IP
  20. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #20
    Also, I noticed you added in

     <input type="hidden" name="isFormSubmitted" />
    Code (markup):
    What does this do?
     
    Matt Ridge, Sep 27, 2011 IP