|
-
Jan 19th, 2014, 03:03 PM
#1
Thread Starter
Hyperactive Member
[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.
-
Jan 19th, 2014, 03:29 PM
#2
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
-
Jan 19th, 2014, 03:33 PM
#3
Thread Starter
Hyperactive Member
Re: My PHP code is showing up underneath the executed code.
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.
-
Jan 19th, 2014, 05:13 PM
#4
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/
-
Jan 19th, 2014, 06:22 PM
#5
Thread Starter
Hyperactive Member
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.
-
Jan 19th, 2014, 06:57 PM
#6
Thread Starter
Hyperactive Member
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.
-
Jan 19th, 2014, 07:21 PM
#7
Thread Starter
Hyperactive Member
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.
-
Jan 20th, 2014, 07:30 AM
#8
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|