[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]
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
1 Attachment(s)
Re: My PHP code is showing up underneath the executed code.
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/
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.
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;}
}
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.
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;
}
}