Echo possibly causing custom template formatting conflict
<p>I've created custom PHP code which allows for user input from two dropdowns and queries a database to return listings which are displayed on a page.  The PHP code works fine as a standalone: <a href="http://projectdemo.in/job_listing/select.php" rel="nofollow">Here</a>.  The problem comes when I add it to a custom Wordpress template.  </p>

<p>The code breaks the template formatting and ends up looking like <a href="http://pinnaclehealthgroup.net/candidate-center/opportunities/" rel="nofollow">this</a>.  Notice the second dropdown and the confirm button are gone.  </p>

<p>I've narrowed the problem down to a PHP echo statement that returns the choices for the first dropdown.  Though I can't figure out why it's causing the problem.   I'm happy to provide more details if needed. thanks!  The code for the custom template is below.  </p>

<pre><code>&lt;?php
/*
Template Name: Jobs Child Page of Parent 2
*/

get_header(); 
the_post();
?&gt;

&lt;?php
if (isset($_GET['cat']))
{
$cat = $_GET['cat'];
}
else
{
$cat = "0";
}
if (isset($_GET['type']))
{
$sub = $_GET['type'];
}
else
{
$sub = "0";
}
?&gt;

    &lt;div id="primary" class="inner-page inner-page-parent"&gt;

        &lt;div id="inner-left"&gt;
            &lt;div id="breadcrumbs"&gt;
                &lt;div class="breadcrumbs"&gt;
                  &lt;?php if(function_exists('bcn_display'))
                  {
                       bcn_display();
                  }?&gt;
                &lt;/div&gt;
            &lt;/div&gt;
                &lt;div id="inner-page-title-block"&gt;

                &lt;div id="inner-page-title-block-right"&gt;
                    &lt;?php echo   get_the_post_thumbnail($post-&gt;ID, "excerpt-thumb"); ?&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div id="inner-content"&gt;
            &lt;?php
        $page_id = get_the_ID();
        if($page_id==2){ ?&gt; &lt;h3&gt;About Us — A Picture of Pinnacle&lt;/h3&gt;&lt;p&gt;&lt;/p&gt; &lt;?php }else {?&gt; 
                    &lt;h3&gt;&lt;?php the_title(); ?&gt;&lt;/h3&gt; &lt;p&gt;&lt;/p&gt;
                     &lt;?php  } ?&gt;    

            &lt;?php the_content(); ?&gt;

         &lt;html&gt;
&lt;head&gt;

    &lt;link rel="stylesheet" href="/joblisting/styles.css" type="text/css" /&gt;

     &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt;
    &lt;!--&lt;script src="jquery.min.js"&gt;&lt;/script&gt;--&gt;
    &lt;script type="text/javascript"&gt;
        $(document).ready(function(){
            //  $("select#type").attr("disabled","disabled");
            $("select#category").change(function(){
                $("select#type").attr("disabled","disabled");
                $("select#type").html("&lt;option&gt;wait...&lt;/option&gt;");

                var id = $("select#category option:selected").attr('value');

                $.post("select_type.php", {id:id}, function(data){
                    $("select#type").removeAttr("disabled");
                    $("select#type").html(data);
                });
            });

            $("form#select_form").submit(function(){
                // Fetch values and parse them to integers
                var cat = parseInt( $("#category").val(), 10 );
                var type =  $("#type").val();


                if(cat&gt;0 &amp;&amp; type&gt;0)
                {
                    $.ajax({
                        type:'GET',
                        url:'/joblisting/display.php',
                        data:'cat='+cat+'&amp;type='+type,
                        success:function(data)
                        {
                            $("#result2").html("");
                            $("#result2").html(data);
                        }
                    });

                }
                else
                {
                    $("#result2").html("you must choose two options!");
                }
                return false;
            });
        });
    &lt;/script&gt;
&lt;/head&gt;

&lt;body style="background:#DADADA;color:#000000;"&gt;
    &lt;?php include "/joblisting/select.class.php"; ?&gt;
    &lt;div&gt;
        &lt;form id="select_form" action=""&gt;
            &lt;div style="border:1px solid #347F82; padding:20px;text-align:left;"&gt;
                &lt;table&gt;
                    &lt;tr&gt;&lt;td&gt;&lt;b&gt;Choose a category:&lt;/b&gt;&lt;/td&gt;
                        &lt;td&gt;
                            &lt;select id="category" name="category" class="wrapper-dropdown"&gt;
                            &lt;?php echo $opt-&gt;ShowCategory($cat); ?&gt;
                            &lt;/select&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;&lt;td&gt;&lt;b&gt;Choose a type:&lt;/b&gt;&lt;/td&gt;
                        &lt;td&gt;
                            &lt;select id="type" name="type" class="wrapper-dropdown"&gt;
                                &lt;option value="0"&gt;choose...&lt;/option&gt;
                               &lt;?php
                                if ($sub != "0")
                                {
                                    echo $opt-&gt;ShowType($cat, $sub);
                                }
                                ?&gt; 
                            &lt;/select&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;&lt;td colspan="2"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
                    &lt;tr align="center"&gt;&lt;td colspan="2"&gt;
                        &lt;input type="submit" value="Confirm" class="classname" /&gt;
                    &lt;/td&gt;&lt;/tr&gt;
                &lt;/table&gt;

            &lt;/div&gt;
        &lt;/form&gt;
        &lt;?php include "/joblisting/display.php"; ?&gt;

        &lt;div id="result2"&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;         


&lt;?php
if($post-&gt;post_parent) {
$parent = get_post($post-&gt;post_parent);


        if($page_id=2){ ?&gt;  &lt;?php }else {?&gt; 

&lt;?php 
echo get_the_title($post-&gt;post_parent); } 
?&gt;&lt;/p&gt;

&lt;?php } ?&gt;


&lt;?php
                $children =&amp; get_children( 'post_type=page&amp; post_parent='.$post-&gt;post_parent );
                foreach($children as $child){
                    ?&gt;




&lt;div class="inner-child-blocks"&gt;                            


                    &lt;/div&gt;





        &lt;?php } ?&gt;


&lt;div style="clear:both;"&gt;&lt;/div&gt;
            &lt;/div&gt;



            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div id="inner-right"&gt;
            &lt;?php if(!dynamic_sidebar("home-widget-column-1")){?&gt;

                &lt;div id="swboc-5" class="widget SWBOC_Widget"&gt;&lt;div class="widget-title-wrapper"&gt;&lt;h2 class="widget-title"&gt;Featured Practice Opportunity&lt;/h2&gt;&lt;/div&gt;&lt;p&gt;&lt;img class="alignnone size-medium wp-image-74" title="sample-2" src="&lt;?php echo bloginfo("template_url"); ?&gt;/images/sample-2-283x185.jpg" alt="" width="283" height="185"&gt;&lt;/p&gt;
                    &lt;p&gt;Quisque in libero ipsum, ut dictum sem. Cras ac ornare purus. Etiam sapien mauris, suscipit at aliquet vel, vestibulum id tortor. Donec porta porta orci ut pharetra. Sed risus nunc, condimentum at ultricies quis, ultrices sed felis. Vivamus ac eros vitae lacus convallis dapibus. Nunc ullamcorper sodales sapien ut consequat. Ut elit leo, iaculis vel tempus nec, feugiat ac est.&lt;br&gt;
                    &lt;a href="#"&gt;READ MORE&lt;/a&gt;&lt;/p&gt;
                    &lt;div style="clear: both;"&gt;&lt;/div&gt;
                &lt;/div&gt;  

                &lt;?php } ?&gt;
            &lt;?php if(!dynamic_sidebar("home-widget-column-2")){ ?&gt;

                &lt;div id="text-6" class="widget widget_text"&gt;
                    &lt;div class="widget-title-wrapper"&gt;&lt;h2 class="widget-title"&gt;Search for Job Opportunities&lt;/h2&gt;&lt;/div&gt;          
                    &lt;div class="textwidget"&gt;
                        &lt;form&gt;
                            &lt;div&gt;&lt;select&gt;&lt;option&gt;Select your profession...&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;
                            &lt;div&gt;&lt;select&gt;&lt;option&gt;Select your specialty...&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;
                            &lt;div&gt;&lt;select&gt;&lt;option&gt;Select your location...&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;
                            &lt;div&gt;&lt;input type="submit" value="SEARCH JOB"/&gt;&lt;/div&gt;
                        &lt;/form&gt;
                    &lt;/div&gt;
                    &lt;div style="clear: both;"&gt;&lt;/div&gt;
                &lt;/div&gt;


                &lt;?php } ?&gt;  
            &lt;?php if(!dynamic_sidebar("home-widget-column-3")){ ?&gt;
                    &lt;div id="advanced-recent-posts-2" class="widget advanced_recent_posts_widget"&gt;&lt;div class="widget-title-wrapper"&gt;&lt;h2 class="widget-title"&gt;Articles, News, Press and Announcements&lt;/h2&gt;&lt;/div&gt;
                        &lt;ul&gt;
                            &lt;li class="recent-post-item first-child"&gt;
                                &lt;p class="post-date"&gt;December 09, 2012, Sunday&lt;/p&gt;
                                &lt;a href="http://test.jkdevices.com/wordpress/?p=41" rel="bookmark" title="Permanent link to A wordpress post #3" class="post-title"&gt;A wordpress post #3&lt;/a&gt;
                                &lt;div class="post-entry"&gt;
                                    &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pellentesque felis ut neque vestibulum eu  &lt;a href="http://test.jkdevices.com/wordpress/?p=41" class="more-link"&gt;Read more&lt;/a&gt; &lt;/p&gt;
                                &lt;/div&gt;
                            &lt;/li&gt;
                            &lt;li class="recent-post-item"&gt;
                                &lt;p class="post-date"&gt;December 09, 2012, Sunday&lt;/p&gt;
                                &lt;a href="http://test.jkdevices.com/wordpress/?p=39" rel="bookmark" title="Permanent link to A wordpress post #2" class="post-title"&gt;A wordpress post #2&lt;/a&gt;
                                &lt;div class="post-entry"&gt;
                                    &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac urna blandit nisi egestas gravida  &lt;a href="http://test.jkdevices.com/wordpress/?p=39" class="more-link"&gt;Read more&lt;/a&gt; &lt;/p&gt;
                                &lt;/div&gt;
                            &lt;/li&gt;
                            &lt;li class="recent-post-item last-child"&gt;
                                &lt;p class="post-date"&gt;December 09, 2012, Sunday&lt;/p&gt;
                                &lt;a href="http://test.jkdevices.com/wordpress/?p=37" rel="bookmark" title="Permanent link to A wordpress post #1" class="post-title"&gt;A wordpress post #1&lt;/a&gt;
                                &lt;div class="post-entry"&gt;
                                    &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pellentesque, odio et molestie scelerisque, tellus  &lt;a href="http://test.jkdevices.com/wordpress/?p=37" class="more-link"&gt;Read more&lt;/a&gt; &lt;/p&gt;
                                &lt;/div&gt;
                            &lt;/li&gt;
                        &lt;/ul&gt;
                        &lt;div style="clear: both;"&gt;&lt;/div&gt;
                    &lt;/div&gt;
                &lt;?php } ?&gt;
        &lt;/div&gt;
        &lt;div style="clear: both;"&gt;&lt;/div&gt;
    &lt;/div&gt;&lt;!-- #primary --&gt;

&lt;?php get_footer(); ?&gt;
</code></pre>
