9 Replies - 1498 Views - Last Post: 20 June 2016 - 05:24 PM Rate Topic: -----

#1 boomer1204   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 18-April 12

Parse error: syntax error, unexpected 'function' (T_FUNCTION)

Posted 19 June 2016 - 05:19 PM

Hey guys,

I will preface this by the fact I do not really "know" php it is just being used for this one instance in my code and throwing me for a loop since it's code I got from googling because I lack knowledge in php. It is working perfectly on my local server running 5.6.10. It is not working on my live server which is running 5.6.21 so I turned on error handling and i'm getting this, Parse error: syntax error, unexpected 'function' (T_FUNCTION) in store_address on line 1. Google keeps saying it's a php version error but i'm on 5.6 on both local and live so i'm a little lost and my php knowledge is MINIMAL at best. Here is the code.

<?php

   	function storeAddress(){

        // Validation
        if(!$_GET['email']){ return "No email address provided"; }

        if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) {
            return "Email address is invalid";
        }

        require_once('MCAPI.class.php');
        // grab an API Key from http://admin.mailchimp.com/account/api/
        $api = new MCAPI('XXXXXXX');

        // grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
        // Click the "settings" link for the list - the Unique Id is at the bottom of that page.
        $list_id = "XXXXXXX";

        if($api->listSubscribe($list_id, $_GET['email'], '') === true) {
            // It worked!
            return 'Success! Check your email to confirm sign up.';
        }else{
            // An error ocurred, return error message
            return 'Error: ' . $api->errorMessage;
        }

    }

    // If being called via ajax, autorun the function
    if(isset($_GET['ajax'])){ echo storeAddress(); }

    ?>




Thanks in advance guys.

Is This A Good Question/Topic? 0
  • +

Replies To: Parse error: syntax error, unexpected 'function' (T_FUNCTION)

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6876
  • View blog
  • Posts: 31,671
  • Joined: 10-May 07

Re: Parse error: syntax error, unexpected 'function' (T_FUNCTION)

Posted 19 June 2016 - 05:20 PM

** renamed title to be more descriptive than "PHP Help" **
Was This Post Helpful? 0
  • +
  • -

#3 boomer1204   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 18-April 12

Re: Parse error: syntax error, unexpected 'function' (T_FUNCTION)

Posted 19 June 2016 - 05:22 PM

Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3151
  • View blog
  • Posts: 11,956
  • Joined: 03-December 12

Re: Parse error: syntax error, unexpected 'function' (T_FUNCTION)

Posted 19 June 2016 - 09:13 PM

There is php code above it, either in the same file or included above it, that is not properly closed.
Was This Post Helpful? 0
  • +
  • -

#5 boomer1204   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 18-April 12

Re: Parse error: syntax error, unexpected 'function' (T_FUNCTION)

Posted 20 June 2016 - 09:07 AM

astonecipher.

Thanks I'll take a look.
Was This Post Helpful? 0
  • +
  • -

#6 boomer1204   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 18-April 12

Re: Parse error: syntax error, unexpected 'function' (T_FUNCTION)

Posted 20 June 2016 - 02:06 PM

So i was looking and I can't find any php that isn't closing. The code above is the entire file and here is the php in my code. This is the only php on there. Again it's working on my local mamp server but not live so i'm still at a loss.

<section id="top">
		<div class="container">
			<div class="row">
				<div class="col-md-7">
				</div>
				<div class="col-md-3 clearfix">
				</div>
				<div class="col-md-2">
				</div>
			</div> <!-- End Of /.row -->
		</div>	<!-- End Of /.Container -->

	<!-- Email Signup Modal Start
	============================= -->
	<div class="modal fade" id='emailCapture' tabindex="-1" role="dialog">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	      </div>
	      <div class='modal-body'>
            <form id="signup" action="" method="get">
          <fieldset style='background: none;'>
            <h3 class='text-center'>RA Seasonings VIP List</h3>
            <img id='modalImage' src="images/newLogoFull.png" alt="Modal Header">
            <h5 class='text-center'>Sign up to get access to new flavors and special promotions</h5>
              <label class='text-center' for="email" id="address-label">
                <span id="response">
                    <?php require_once('inc/store-address.php');
                    if($_GET['submit']){ echo storeAddress(); } ?>
                  </span>
              </label>
              <input class='form-control' type="text" name="email" id="email" placeholder='Email Address'/>
              <input id='submitButton' type="submit" name="submit" value='Submit' class="btn btn-success text-center" alt="Submit" />

              <div class='text-center' id="no-spam">We'll never spam or give this address away</div>
          </fieldset>
        </form>
        </div>
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
	<!-- MODAL Start



the php again. This is all the code on this file

<?php
    function storeAddress(){

        // Validation
        if(!$_GET['email']){ return "No email address provided"; }

        if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) {
            return "Email address is invalid";
        }

        require_once('MCAPI.class.php');
        // grab an API Key from http://admin.mailchimp.com/account/api/
        $api = new MCAPI('XXXXXXX');

        // grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
        // Click the "settings" link for the list - the Unique Id is at the bottom of that page.
        $list_id = "XXXXXXX";

        if($api->listSubscribe($list_id, $_GET['email'], '') === true) {
            // It worked!
            return 'Success! Check your email to confirm sign up.';
        }else{
            // An error ocurred, return error message
            return 'Error: ' . $api->errorMessage;
        }

    }

    // If being called via ajax, autorun the function
    if(isset($_GET['ajax'])){ echo storeAddress(); }

    ?>


Thanks again for the help.
Was This Post Helpful? 0
  • +
  • -

#7 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3151
  • View blog
  • Posts: 11,956
  • Joined: 03-December 12

Re: Parse error: syntax error, unexpected 'function' (T_FUNCTION)

Posted 20 June 2016 - 02:09 PM

Line 29 of the html file, what's in that?
Was This Post Helpful? 0
  • +
  • -

#8 boomer1204   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 18-April 12

Re: Parse error: syntax error, unexpected 'function' (T_FUNCTION)

Posted 20 June 2016 - 02:11 PM

the php I shared is the file it is requiring on line 29.
Was This Post Helpful? 0
  • +
  • -

#9 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2766
  • View blog
  • Posts: 8,072
  • Joined: 15-January 14

Re: Parse error: syntax error, unexpected 'function' (T_FUNCTION)

Posted 20 June 2016 - 03:15 PM

That file doesn't have any syntax errors. You can copy and paste the code into an online syntax checker to verify. Maybe the file was saved wrong or something, but the code is fine.
Was This Post Helpful? 0
  • +
  • -

#10 boomer1204   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 18-April 12

Re: Parse error: syntax error, unexpected 'function' (T_FUNCTION)

Posted 20 June 2016 - 05:24 PM

Apparently when I upload it to my server it totally jacks the spacing and what not up. Got that fixed.

Thanks again for all the help guys!!

This post has been edited by boomer1204: 20 June 2016 - 05:30 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1