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!