Basic PHP MYSQL problem

I am very new to php mysql and am using Kevin Yank’s Book “Build
your own Database Driven Web Site using PHP and MySQL - 4th Ed.”

I wrote out the following code exactly as it is in the book as follows:

if (!mysqli_set_charset($link, ‘utf8’))

and have tried everything I can think of to get it to work however all I get is the following message

Parse error: syntax error, unexpected T_STRING in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Connect\index.php on line 9

Can anyone tell me what is wrong?

Thanks for any help!

If that is line 9, then it’s probably something immediately preceding this code which is wrong.

Here are all 23 lines

Thanks for the help!

<?PHP
$link = mysqli_connect(‘localhost’, ‘root’, ‘Lmk01only’);
if (!$link)
{
$output = ‘Unable to connect to the database server.’;
include 'output.html.php
exit();
}
if (!mysqli_set_charset($link, ‘utf8’))
{
$output = ‘Unable to set database connection encoding.’;
include 'output.html.php;
exit();
}
if (!mysql_select_db($link, ‘ijdb’))
{
$output = ‘Unable to locate the joke database.’;
include ‘output.html.php’;
exit();
}
$output = ‘Database connection established.’;
include 'output.html.php;
?>

include 'output.html.php

This line here you’re missing the ending quote and semicolon.

The error indicates line 9 because that’s where the PHP parser found the first single quote to match the one you omitted 3 lines earlier – it assumes this is the end of that string, but given that assumption the code following that is not valid PHP syntax, and it must give up and present an error.

Dan

Thankyou. After your first post I looked back and found I was missing the Endquote previously. This caused me to look through it all again and found a couple other errors I hadn’t noticed.

Thanks for your help on such an obvious blunder.

Leo

Try to use some text editor with code highlight feature.
It will show you where the problem is.
Even this forum can do it, with properly chosen language to highlight
Look, it highlights exit() as if it is string, but it is function:

<?PHP
$link = mysqli_connect('localhost', 'root', 'Lmk01only');
if (!$link)
{
$output = 'Unable to connect to the database server.';
include 'output.html.php
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
$output = 'Unable to set database connection encoding.';

?>

it won’t help you with a semicolon though. But this kind of error will hint you to check semicolons above.