Title: php help &#8211; syntax errors?
Last modified: August 30, 2016

---

# php help – syntax errors?

 *  Resolved [jboepple](https://wordpress.org/support/users/jboepple/)
 * (@jboepple)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/php-help-syntax-errors/)
 * Hi! I don’t know if this is ok to ask on the forum, but my programmer is out 
   of town and this designer needs a little help.
 * I have an ecommerce store, and one of the post IDs needs to operate different
   than the rest. Here’s the code for that specific product:
 *     ```
       <?php if ( $postID == "2352" ) { ?>
             <div class="row closing-cta">
               <div class="col-md-9">
                 Alphabet Energy <?php echo roots_title(); ?>
             		<p class="purchase_price">$<?=$purchase_price?></p>
               </div>
               <div class="col-md-3">
                 <a href="/product/powermodule-developer-kit/?add-to-cart=2352" rel="nofollow" data-product_id="2352" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>
               </div>
             </div>
       ```
   
 * Now I need to do the same to a second product. The links will change, so I know
   I can’t just change it to this:
 * `<?php if (in_array($postID, array(“2352”, “xxx”)) ?>`
 * So I duplicated the whole string of code and changed the product number and links
   to this:
 *     ```
       <?php if ( $postID == "2352" ) { ?>
             <div class="row closing-cta">
               <div class="col-md-9">
                 Alphabet Energy <?php echo roots_title(); ?>
             		<p class="purchase_price">$<?=$purchase_price?></p>
               </div>
               <div class="col-md-3">
                 <a href="/product/powermodule-developer-kit/?add-to-cart=2352" rel="nofollow" data-product_id="2352" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>
               </div>
             </div>
                   <?php if ( $postID == "2397" ) { ?>
             <div class="row closing-cta">
               <div class="col-md-9">
                 Alphabet Energy <?php echo roots_title(); ?>
             		<p class="purchase_price">$<?=$purchase_price?></p>
               </div>
               <div class="col-md-3">
                 <a href="/product/powermodule-dev-kit/?add-to-cart=2397" rel="nofollow" data-product_id="2397" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>
               </div>
             </div>
       ```
   
 *  but then I got a syntax error at the bottom of my php file:
 *     ```
       </div><!-- /.main -->
       <?php endwhile; ?>
       ```
   
 * Is there something else I need to add since I added the second product’s code
   at the top? I just don’t know what to do! Thanks in advance. (I’d give a link
   to the site but it is all password protected so I can’t!)
 * Here’s the whole page in case it makes a difference:
 *     ```
       <?php while (have_posts()) : the_post(); ?>
       <?php
       	$postID = get_the_ID();
       	$postmeta = get_post_meta($postID);
       	$subtitle = (isset($postmeta['subtitle']))?$postmeta['subtitle'][0]:'';
       	$features = (isset($postmeta['features']))?$postmeta['features'][0]:'';
       	$youtube = (isset($postmeta['youtube']))?$postmeta['youtube'][0]:'';
         $quote = (isset($postmeta['quote']))?$postmeta['quote'][0]:'';
         $product_intro = (isset($postmeta['product_intro']))?$postmeta['product_intro'][0]:'';
         $buy_subtitle = (isset($postmeta['buy_subtitle']))?$postmeta['buy_subtitle'][0]:'';
         $buy_product_intro = (isset($postmeta['buy_product_intro']))?$postmeta['buy_product_intro'][0]:'';
         $purchase_price = (isset($postmeta['purchase_price']))?$postmeta['purchase_price'][0]:'';
       ?>
       <? /* <div class="main col-sm-8 col-sm-offset-1" role="main"> */?>
       <div class="main col-sm-12" role="main">
       	<article <?php post_class(); ?>>
   
       		<?php if($buy_subtitle) { ?>
       		<h2 class="subtitle"><?=$buy_subtitle?></h2>
       		<?php } ?>
   
       		<?php if($buy_product_intro) { ?>
           <div class="product-intro">
             <p><? echo $buy_product_intro?></p>
           </div>
           <?php } ?>
   
       		<?php if($youtube) { ?>
       		<div class="video-container">
       			<iframe width="100%" src="//www.youtube.com/embed/<?=$youtube?>?rel=0" frameborder="0" allowfullscreen></iframe>
       		</div>
       		<?php } ?>
   
             <?php if ( $postID == "2352" ) { ?>
             <div class="row closing-cta">
               <div class="col-md-9">
                 Alphabet Energy <?php echo roots_title(); ?>
             		<p class="purchase_price">$<?=$purchase_price?></p>
               </div>
               <div class="col-md-3">
                 <a href="/product/powermodule-developer-kit/?add-to-cart=2352" rel="nofollow" data-product_id="2352" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>
               </div>
             </div>
                   <?php if ( $postID == "2397" ) { ?>
             <div class="row closing-cta">
               <div class="col-md-9">
                 Alphabet Energy <?php echo roots_title(); ?>
             		<p class="purchase_price">$<?=$purchase_price?></p>
               </div>
               <div class="col-md-3">
                 <a href="/product/powermodule-dev-kit/?add-to-cart=2397" rel="nofollow" data-product_id="2397" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>
               </div>
             </div>
              <?php } else { ?>
              <div class="row">
   
             		<?php if($subtitle) { ?>
             		<h2 class="subtitle"><?=$subtitle?></h2>
             		<?php } ?>
   
             		<?php if($product_intro) { ?>
             		<div class="product-intro">
                   <p><? echo $product_intro?></p>
   
                   <?php if ( $postID == "2103" ) {
                   	echo '<p><a href="http://www.alphabetenergy.com/products/powermodule-pre-order-form/" class="btn btn-blue btn-lg" data-title="PRE-ORDER NOW" role="button">Pre-order Now</a></p>';
                    } else {
                     echo '<p><a href="#" class="btn btn-blue btn-lg request-info-link" data-title="REQUEST A BROCHURE" data-item="Request a Brochure: <? the_title(); ?>" role="button">Request Brochure</a></p>';
                      } ?>
   
                 </div>
               </div>
           		<?php } ?>
   
             <?php } ?>
   
           <?php the_content(); ?>
   
           <div class="row closing-cta">
             <div class="col-md-9">
               Alphabet Energy <?php echo roots_title(); ?>
           		<?php if($purchase_price) { ?>
           		<p class="purchase_price">$<?=$purchase_price?></p>
           		<?php } ?>
             </div>
             <div class="col-md-3">
               <?php if ( $postID == "2103" ) {
               	echo '<a href="http://www.alphabetenergy.com/products/powermodule-pre-order-form/" class="btn btn-blue btn-lg" data-title="PRE-ORDER NOW" role="button">Pre-order Now</a>';
                } elseif( $postID == "2352") {
                 echo '<a href="/product/powermodule-developer-kit/?add-to-cart=2352" rel="nofollow" data-product_id="2352" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>';
                } else {
                 echo '<a href="#" class="btn btn-blue btn-lg request-info-link" data-title="REQUEST A BROCHURE" data-item="Request a Brochure: <? the_title(); ?>" role="button">Request Brochure</a>';
               } ?>
   
             </div>
           </div>
   
       	</article>
       </div><!-- /.main -->
       <?php endwhile; ?>
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 9 months ago](https://wordpress.org/support/topic/php-help-syntax-errors/#post-6374884)
 * You’re not using correct speech mark characters, look:
 *     ```
       <?php if (in_array($postID, array(“2352”, “xxx”)) ?>
       ```
   
 * It should be this:
 *     ```
       <?php if (in_array($postID, array("2352", "xxx")) ?>
       ```
   
 *  Thread Starter [jboepple](https://wordpress.org/support/users/jboepple/)
 * (@jboepple)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/php-help-syntax-errors/#post-6374885)
 * hi Andrew!
 * I think that’s just a copy and paste error in this instance — it’s not like that
   in the code.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/php-help-syntax-errors/#post-6374887)
 * you need to close the first if statement properly –
 * [http://php.net/manual/en/control-structures.if.php](http://php.net/manual/en/control-structures.if.php)
 * possible better, work with if/elseif/else [http://php.net/manual/en/control-structures.elseif.php](http://php.net/manual/en/control-structures.elseif.php)
 *  Thread Starter [jboepple](https://wordpress.org/support/users/jboepple/)
 * (@jboepple)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/php-help-syntax-errors/#post-6374888)
 * thanks for the reply alchymyth!
 * I may have this wrong, but… I need to add an `<?php endif ?>` somewhere? can 
   you tell me where?
 *  Thread Starter [jboepple](https://wordpress.org/support/users/jboepple/)
 * (@jboepple)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/php-help-syntax-errors/#post-6374893)
 * got the answer from a friend:
 * change the line `<?php if ( $postID == "2397" ) { ?>` to `<?php } else if ( $
   postID == "2397" ) { ?>`
 * it needed `}` to close the first if
 * Thanks everyone!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘php help – syntax errors?’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [jboepple](https://wordpress.org/support/users/jboepple/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/php-help-syntax-errors/#post-6374893)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
