Results 1 to 8 of 8

Thread: [RESOLVED] My PHP code is showing up underneath the executed code.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Resolved [RESOLVED] My PHP code is showing up underneath the executed code.

    I have spent the last couple of hours developing my code and it seems to be working fine. However i just noticed that the code had started showing up underneath the executed code, i have tried commenting out the lines of code i edited in the last half hour with no fix.

    Im using wordpress 3.8 on a localhost.

    Code:
    <?php
    [insert_php]
    function IsPostcode($postcode){
    	$postcode = strtoupper(str_replace(' ','',$postcode));
    	if(preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$postcode) || preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/",$postcode) || preg_match("/^GIR0[A-Z]{2}$/",$postcode))
    	return true;
    	else
    	return false;
    }
    
    				
    				$ORIGIN = $row[ORIGIN];
    				//postcode
    				if (IsPostcode($ORIGIN))
    				{echo "<tr><td colspan=\"1\" class=\"bold\">Address:</td><td colspan=\"1\"><input type=\"text\" name=\"P_ADDRESS\"></td>";
    				echo "<td colspan=\"1\" class=\"bold\">Postcode:</td><td colspan=\"1\"><input type=\"hidden\" name=\"P_POSTCODE\" value=\"".$row[ORIGIN]."\"><input type=\"text\" name=\"P_POSTCODE1\" value=\"".$row[ORIGIN]."\" disabled></td></tr>\n";}
    				//airport
    				else if (strpos($ORIGIN, "AIRPORT") !== FALSE){
    				echo "<tr><td colspan=\"1\" class=\"bold\">Airport:</td><td colspan=\"3\"><input type=\"HIDDEN\" name=\"P_ADDRESS\" value=\"".$row[ORIGIN]."\"><input type=\"text\" name=\"P_ADDRESS1\" value=\"".$row[ORIGIN]."\"disabled></td></tr>\n";
    				echo "<tr><td colspan=\"1\" class=\"bold\">Terminal:</td><td colspan=\"1\"><input type=\"text\" name=\"P_TERMINAL\" value=\"\"></td><td colspan=\"1\" class=\"bold\">Flight No:</td><td colspan=\"1\"><input type=\"text\" name=\"P_FLIGHTNO\" value=\"\"></td></tr>\n";}
    				else{
    				//location
    				echo "<tr><td colspan=\"1\" class=\"bold\">Address:</td><td colspan=\"3\"><input type=\"HIDDEN\" name=\"P_ADDRESS\" value=\"".$row[ORIGIN]."\"><input type=\"text\" name=\"P_ADDRESS1\"value=\"".$row[ORIGIN]."\" disabled></td>";}	
    				echo "<tr class=\"title\"  bgcolor=\"#4382b5\"><td colspan='4'>Destination Details</td></tr>\n";
    				
    				$DESTINATION = $row[DESTINATION];
    				//postcode
    				if (IsPostcode($DESTINATION))
    				{echo "<tr><td colspan=\"1\" class=\"bold\">Address:</td><td colspan=\"1\"><input type=\"text\" name=\"D_ADDRESS\"></td>";
    				echo "<td colspan=\"1\" class=\"bold\">Postcode:</td><td colspan=\"1\"><input type=\"hidden\" name=\"D_POSTCODE\" value=\"".$row[DESTINATION]."\"><input type=\"text\" name=\"D_POSTCODE1\" value=\"".$row[DESTINATION]."\" disabled></td></tr>\n";}
    				//airport
    				else if (strpos($DESTINATION, "AIRPORT") !== FALSE){
    				echo "<tr><td colspan=\"1\" class=\"bold\">Airport:</td><td colspan=\"3\"><input type=\"HIDDEN\" name=\"D_ADDRESS\" value=\"".$row[DESTINATION]."\"><input type=\"text\" name=\"D_ADDRESS1\" value=\"".$row[DESTINATION]."\"disabled></td></tr>\n";}
    				else{
    				//location
    				echo "<tr><td colspan=\"1\" class=\"bold\">Address:</td><td colspan=\"3\"><input type=\"HIDDEN\" name=\"D_ADDRESS\" value=\"".$row[DESTINATION]."\"><input type=\"text\" name=\"D_ADDRESS1\"value=\"".$row[DESTINATION]."\" disabled></td>";}
    				
    [/insert_php]
    Last edited by chris1990; Jan 20th, 2014 at 12:29 PM.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: My PHP code is showing up underneath the executed code.

    What do you mean by "the code had started showing up underneath the executed code"?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: My PHP code is showing up underneath the executed code.

    Name:  error.png
Views: 111
Size:  84.4 KB
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: My PHP code is showing up underneath the executed code.

    The insertphp plugin does not want you to use <?php, but rather just the [insert_php] line.

    Try removing the <?php and ?> from your code.

    Source: http://wordpress.org/plugins/insert-php/

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: My PHP code is showing up underneath the executed code.

    Ive been using it like that through development. Anyway i did what u said and its still the same.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: My PHP code is showing up underneath the executed code.

    i've narrowed it down to this function

    Code:
    function IsPostcode($postcode){
    	$postcode = strtoupper(str_replace(' ','',$postcode));
    	if(preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$postcode) || preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/",$postcode) || preg_match("/^GIR0[A-Z]{2}$/",$postcode))
    	{return true;}
    	else
    	{return false;}
    }
    Last edited by chris1990; Jan 19th, 2014 at 08:50 PM.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: My PHP code is showing up underneath the executed code.

    I've figured out it has something to do with this code untill adding this part of the code, no code shows below.

    Code:
    $ORIGIN = $row[ORIGIN];
    				//postcode
    				if (IsPostcode($ORIGIN)){
    				echo "<tr><td colspan=\"1\" class=\"bold\">Address:</td><td colspan=\"1\"><input type=\"text\" name=\"P_ADDRESS\"></td>";
    				echo "<td colspan=\"1\" class=\"bold\">Postcode:</td><td colspan=\"1\"><input type=\"hidden\" name=\"P_POSTCODE\" value=\"".$row[ORIGIN]."\"><input type=\"text\" name=\"P_POSTCODE1\" value=\"".$row[ORIGIN]."\" disabled></td></tr>\n";
    				}
    				//airport
    				else if (strpos($ORIGIN, "AIRPORT") !== FALSE){
    				echo "<tr><td colspan=\"1\" class=\"bold\">Airport:</td><td colspan=\"3\"><input type=\"HIDDEN\" name=\"P_ADDRESS\" value=\"".$row[ORIGIN]."\"><input type=\"text\" name=\"P_ADDRESS1\" value=\"".$row[ORIGIN]."\"disabled></td></tr>\n";
    				echo "<tr><td colspan=\"1\" class=\"bold\">Terminal:</td><td colspan=\"1\"><input type=\"text\" name=\"P_TERMINAL\" value=\"\"></td><td colspan=\"1\" class=\"bold\">Flight No:</td><td colspan=\"1\"><input type=\"text\" name=\"P_FLIGHTNO\" value=\"\"></td></tr>\n";
    				}
    				else{
    				//location
    				echo "<tr><td colspan=\"1\" class=\"bold\">Address:</td><td colspan=\"3\"><input type=\"HIDDEN\" name=\"P_ADDRESS\" value=\"".$row[ORIGIN]."\"><input type=\"text\" name=\"P_ADDRESS1\"value=\"".$row[ORIGIN]."\" disabled></td>";
    				}	
    				echo "<tr class=\"title\"  bgcolor=\"#4382b5\"><td colspan='4'>Destination Details</td></tr>\n";
    i have removed the IsPostcode($postcode) function and all calls to it, and the page displays as its suppose to.
    Last edited by chris1990; Jan 19th, 2014 at 08:52 PM. Reason: update:
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: My PHP code is showing up underneath the executed code.

    I've fixed it now,i included this function in the functions.php in my theme folder rather than on the page it's self.

    I think it had something to do with the insert php plugin not being compatible with the '||' operator, as i remember having a problem with them the other day.

    Code:
    //validate postcode
    function IsPostcode($postcode)
    {
        $postcode = strtoupper(str_replace(' ','',$postcode));
        if(preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$postcode) || preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/",$postcode) || preg_match("/^GIR0[A-Z]{2}$/",$postcode))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    Last edited by chris1990; Jan 20th, 2014 at 12:29 PM.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width