Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've been trying to set up a web service to connect to an iPhone app using a great tutorial from Ray Wenderlich

I've confirmed that the database is set up correctly in mysql and that php is working on my system as well. I copied and pasted the following code into index.php:

<?php
class RedeemAPI {
    private $db;

    // Constructor - open DB connection
    function __construct() {
        $this->db = new mysqli('localhost', 'username', 'password', 'promos');
        $this->db->autocommit(FALSE);
    }
    // Destructor - close DB connection
    function __destruct() {
        $this->db->close();
    }
    // Main method to redeem a code
    function redeem() {
        // Print all codes in database
        $stmt = $this->db->prepare('SELECT id, code, unlock_code, uses_remaining FROM rw_promo_code');
        $stmt->execute();
        $stmt->bind_result($id, $code, $unlock_code, $uses_remaining);
        while ($stmt->fetch()) {
            echo "$code has $uses_remaining uses remaining!";
        }
        $stmt->close();
    }
}
$api = new RedeemAPI;
$api->redeem();
?>

However, when I try to access this file I get the following error:

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in /Users/Austin/Sites/Website/index.php on line 10

I've searched the net for related errors, but to no avail. If anyone can see something wrong with the code or have any suggestions, that would be greatly appreciated. Thanks!

share|improve this question
1  
What version of PHP? – Mark Baker Nov 23 '11 at 17:37
1  
which line is no. 10 – Arif Nov 23 '11 at 17:38
1  
I've sometimes had goofy errors because of newlines after copying and pasting something from another source. If you have an editor that can convert your newlines to something standard, maybe give that a shot. – jprofitt Nov 23 '11 at 17:39
I'm using version 5.3.6 (The one that is bundled with OS X Lion). Line 10 is between the end of the __construct function and the // Destructor comment in my file. – Austin Borden Nov 23 '11 at 18:42
Just an idea: you are sure / are just regular slashes and not something scary, that word (or whatever) uses instead? – KingCrunch Nov 23 '11 at 18:45
show 2 more comments

closed as too localized by Kevin Peno, edorian, Gordon, Álvaro G. Vicario, ChrisF Nov 24 '11 at 21:55

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

I had this same problem once with an invisible space mark. It looked like space but was some ctrl character. Deleting all the spaces on the line and adding them back sorted the problem.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.