Syntax error

I ahve been staring at this syntax error for two hours now and still not having a clue. I am trying to work through Build Your Own Database Driven Web Site Using PHP & MySQL, page 132 ff.

Here’s the form at the form.html.php:

<form action=“?” method=“post”>
<div>
<label for=“Namn”>Lägg till författare:</label>
<input type=“text” id=“fnamn” name=“fnamn”>
</div>
<div><input type=“submit” value=“Add”/></div>
</form>

Here’s the index.php:

<?php

if (get_magic_quotes_gpc())
{
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map(‘stripslashes_deep’, $value) :
stripslashes($value);
return $value;
}
$_POST = array_map(‘stripslashes_deep’, $_POST);
$_GET = array_map(‘stripslashes_deep’, $_GET);
$_COOKIE = array_map(‘stripslashes_deep’, $_COOKIE);
$_REQUEST = array_map(‘stripslashes_deep’, $_REQUEST);
}

include ‘form.html.php’;

$link = mysqli_connect(‘localhost’, ‘root’, ‘xxxx’);
if (!$link)
{
$error = ‘Unable to connect to the database server.’;
include ‘error.html.php’;
exit();
}
if (!mysqli_set_charset($link, ‘utf8’))
{
$output = ‘Unable to set database connection encoding.’;
include ‘output.html.php’;
exit();
}
if (!mysqli_select_db($link, ‘forfattare’))
{
$error = ‘Unable to locate the forfattare database.’;
include ‘error.html.php’;
exit();
}

if (isset($_POST[‘fnamn’]))
{
$fnamn = mysqli_real_escape_string($link, $_POST[‘fnamn’]);
$sql = ‘INSERT INTO forfattare SET
fnamn="’ . $fnamn . '";
if (!mysqli_query($link, $sql))
{
$error = 'Error adding submitted joke: ’ . mysqli_error($link);
include ‘error.html.php’;
exit();
}
header(‘Location: .’);
exit();
}

?>

Here’s the error message:

Parse error: syntax error, unexpected T_STRING in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\index.php on line 58

Line 58 is this line: $error = 'Error adding submitted joke: ’ . mysqli_error($link);

I CANNOT see what’s wrong. All help is deeply appreciated!

Put code tags around your code when you post code here.

<form action="?" method="post">
<div>
<label for="Namn">Lägg till författare/label>
<input type="text" id="fnamn" name="fnamn">
</div>
<div><input type="submit" value="Add"/></div>
</form>
<?php


if (get_magic_quotes_gpc())
{
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}


include 'form.html.php';

$link = mysqli_connect('localhost', 'root', 'xxxx');
if (!$link)
{
$error = 'Unable to connect to the database server.';
include 'error.html.php';
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
$output = 'Unable to set database connection encoding.';
include 'output.html.php';
exit();
}
if (!mysqli_select_db($link, 'forfattare'))
{
$error = 'Unable to locate the forfattare database.';
include 'error.html.php';
exit();
}

if (isset($_POST['fnamn']))
{
$fnamn = mysqli_real_escape_string($link, $_POST['fnamn']);
$sql = 'INSERT INTO forfattare SET
fnamn="' . $fnamn . '";
if (!mysqli_query($link, $sql))
{
$error = 'Error adding submitted joke: ' . mysqli_error($link);
include 'error.html.php';
exit();
}
header('Location: .');
exit();
}


?>

See everything getting red at the end? Long live coloured syntax :smiley:
You’re missing a closing ’ at the end of your query ($sql).

yup, from my experience that error usually means you are missing a closing ’ " or ; at the end of a line of code.

That’s why I recommend to use a PHP IDE which tracks such syntax errors instantly. I love PHPDesigner 7.2.

Thank you all very much !:slight_smile: