0

I have searched here, php.net and mysql.com. I cannot see what I am doing wrong. Can anyone see the error in my code?

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home4/vernsouthern/public_html/testsites/winenotes/main.php on line 47

<!DOCTYPE html>
<html>
<body>
<?php
$servername = "localhost";
$username = "myusername";
$password = "mypassword";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
if(!isset($_POST['country_type']) ||
    !isset($_POST['region_type']) ||
    !isset($_POST['wine_type']) ||
    !isset($_POST['vintage_type'])) {
    died('<p>We are sorry, but there appears to be a problem with the form you submitted.</p>');
}
$country_type = $_POST['country_type'];
$region_type  = $_POST['region_type'];
$wine_type = $_POST['wine_type'];
$vintage_type  = $_POST['vintage_type'];
$sql = "* FROM wp_winenotes 
WHERE Country = $country_type 
AND Wine = $wine_type 
AND Region = $region_type 
AND Vintage = $vintage_type;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each selected row
    while($row = $result->fetch_assoc()) {
        $wine = iconv('ASCII', 'UTF-8//IGNORE', $row['Wine']);
        $note = iconv('ASCII', 'UTF-8//IGNORE', $row['Note']);
        echo "<br> id: ". $row['id']. " - Wine: " . $wine . "<br>Note: " . $note . "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?> 
</body>
</html>

This is the first error:

$wine = iconv('ASCII', 'UTF-8//IGNORE', $row['Wine']);

1 Answers1

0

You forgot to add a double quote (") before the semicolon (;) here:

$sql = "* FROM wp_winenotes 
WHERE Country = $country_type 
AND Wine = $wine_type 
AND Region = $region_type 
AND Vintage = $vintage_type;

Here is the full code fixed:

<!DOCTYPE html>
<html>
<body>
<?php
$servername = "localhost";
$username = "myusername";
$password = "mypassword";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
if(!isset($_POST['country_type']) ||
    !isset($_POST['region_type']) ||
    !isset($_POST['wine_type']) ||
    !isset($_POST['vintage_type'])) {
    die('<p>We are sorry, but there appears to be a problem with the form you submitted.</p>');
}
$country_type = $_POST['country_type'];
$region_type  = $_POST['region_type'];
$wine_type = $_POST['wine_type'];
$vintage_type  = $_POST['vintage_type'];
$sql = "* FROM wp_winenotes 
WHERE Country = $country_type 
AND Wine = $wine_type 
AND Region = $region_type 
AND Vintage = $vintage_type";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each selected row
    while($row = $result->fetch_assoc()) {
        $wine = iconv('ASCII', 'UTF-8//IGNORE', $row['Wine']);
        $note = iconv('ASCII', 'UTF-8//IGNORE', $row['Note']);
        echo "<br> id: ". $row['id']. " - Wine: " . $wine . "<br>Note: " . $note . "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?> 
</body>
</html>

EDIT

Another typo found in code, corrected in edit.

    died('<p>We are sorry, but there appears to be a problem with the form you submitted.</p>');

should be:

    die('<p>We are sorry, but there appears to be a problem with the form you submitted.</p>');