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!
/
are just regular slashes and not something scary, that word (or whatever) uses instead? – KingCrunch Nov 23 '11 at 18:45