Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I cannot seem to find where I missed closing a statement.

I keep getting this error

PHP Parse error:  syntax error, unexpected $end in /var/www/html/gs_phonebook.php on line 50

This is my code.

[php]
<?php
// File: gs_phonebook.php
// version: 1.0
// Description: Generating a XML Phonebook from FreePBX MySQL DB
//!!Enable for Debug only!!
error_reporting(E_ALL);
ini_set("display_errors",ON);

// Database settings
$DBhost="comms.****";
$DBuser="****";
$DBpass="****";
$DBdatabase="asterisk";

// Connect to the Database and get all devices
$DBlink=mysql_connect($DBhost,$DBuser,$DBpass) or die("Could not connect to host.");
mysql_select_db($DBdatabase,$DBlink) or die("Could not find database.");
$DBquery="SELECT user,description FROM devices ORDER BY descriptionASC";
$QUERYresult=mysql_query($DBquery,$DBlink) or die("Data not found.");

//Setup XMLWriter
$writer =newXMLWriter();
$writer->openURI('/tftpboot/gs_phonebook.xml');
$writer->setIndent(4);

//Beginn output
$writer->startDocument('1.0');
$writer->startElement('AddressBook');

//Add extensions / contacts from devices to the xml phonebook
while($contact=mysql_fetch_array($QUERYresult)){
$writer->startElement('Contact');
$writer->writeElement('LastName',$contact['description']);
$writer->writeElement('FirstName',");
$writer->startElement('Phone');
$writer->writeElement('phonenumber',$contact[user]);
$writer->writeElement('accountindex','0');
$writer->endElement();
$writer->endElement();
}

$writer->endElement();
$writer->endDocument();$writer->flush();
?>
[/php]
share|improve this question

5 Answers 5

You should add double quote in place of single quote. If you want to add single quote then add ''.

$writer->writeElement("FirstName","");

Double quote will not generate any error.So remove single quote and add double quote.

share|improve this answer

Error in this line

$writer->writeElement('FirstName',");

You can give two double quotes as

$writer->writeElement('FirstName',"");

or Two single quotes as

$writer->writeElement('FirstName','');
share|improve this answer

You haven't closed the double quotation at this line

$writer->writeElement('FirstName',");

You may use this instead

<?php
// File: gs_phonebook.php
// version: 1.0
// Description: Generating a XML Phonebook from FreePBX MySQL DB
//!!Enable for Debug only!!
error_reporting(E_ALL);
ini_set("display_errors",ON);

// Database settings
$DBhost="comms.****";
$DBuser="****";
$DBpass="****";
$DBdatabase="asterisk";

// Connect to the Database and get all devices
$DBlink=mysql_connect($DBhost,$DBuser,$DBpass) or die("Could not connect to host.");
mysql_select_db($DBdatabase,$DBlink) or die("Could not find database.");
$DBquery="SELECT user,description FROM devices ORDER BY descriptionASC";
$QUERYresult=mysql_query($DBquery,$DBlink) or die("Data not found.");

//Setup XMLWriter
$writer =newXMLWriter();
$writer->openURI('/tftpboot/gs_phonebook.xml');
$writer->setIndent(4);

//Beginn output
$writer->startDocument('1.0');
$writer->startElement('AddressBook');

//Add extensions / contacts from devices to the xml phonebook
while($contact=mysql_fetch_array($QUERYresult)){
$writer->startElement('Contact');
$writer->writeElement('LastName',$contact['description']);
$writer->writeElement('FirstName',"");
$writer->startElement('Phone');
$writer->writeElement('phonenumber',$contact[user]);
$writer->writeElement('accountindex','0');
$writer->endElement();
$writer->endElement();
}

$writer->endElement();
$writer->endDocument();$writer->flush();
?>
share|improve this answer

As the code highlighting shows, on this line:

$writer->writeElement('FirstName',");

You have a mismatched double quote- you need '' instead of " (or something instead of ")

share|improve this answer
$writer->writeElement('FirstName',");

That looks like a double quote rather than 2 single quotes. You can tell from the messed up colouring on the SO codeblock.

Should be like this:

$writer->writeElement('FirstName','');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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