I have a problem with PHP and, although I spent a whole hour trying to find what's wrong, I can't find anything in the code.
I'm working with a MySQL database and an input form. The form should be used to add entries to a specific table in the database. However, it gives a "Parse error: syntax error, unexpected '}'" whenever I hit the "Submit" button.
I tried everything but nothing worked.
This is the code:
<?php
include 'config.php';
session_start();
if (!isset($_SESSION['login'])){
header("Location: index.html");
}
if(isset($_POST['submit']) && ($_POST['submit']=="Invia")){
if(isset($_POST['section'])){
$section = addslashes(filter_var($_POST['section'], FILTER_SANITIZE_STRING));
} else {
echo "Devi selezionare una sezione";
}
if(isset($_POST['offer'])){
$offer = addslashes(filter_var($_POST['offer'], FILTER_SANITIZE_STRING));
}
if(isset($_POST['title'])){
$title = addslashes(filter_var($_POST['title'], FILTER_SANITIZE_STRING));
} else {
echo "Devi impostare il nome del viaggio";
}
if(isset($_POST['datestart'])){
$datestart = date('Ymd', strtotime($_POST['datestart']));
} else {
echo "Devi selezionare una data di inizio";
}
if(isset($_POST['dateend'])){
$dateend = date('Ymd', strtotime($_POST['dateend']));
} else {
echo "Devi selezionare una data di fine";
}
if(isset($_POST['itinerary'])){
$itinerary = addslashes(filter_var($_POST['itinerary'], FILTER_SANITIZE_STRING));
} else {
echo "Devi inserire un itinerario";
}
if(isset($_POST['price'])){
$price = addslashes(filter_var($_POST['price'], FILTER_SANITIZE_STRING));
} else {
echo "Devi inserire un prezzo";
}
if(isset($_POST['includes'])){
$includes = addslashes(filter_var($_POST['includes'], FILTER_SANITIZE_STRING));
} else {
echo "Devi inserire La quota comprende!";
}
if(isset($_POST['pdfname'])){
$pdfname = addslashes(filter_var($_POST['pdfname'], FILTER_SANITIZE_STRING));
} else {
echo "Devi inserire un nome per il pdf";
}
if(isset($_POST['section']) && isset($_POST['title']) && isset($_POST['datestart']) && isset($_POST['dateend']) && isset($_POST['itinerary']) && isset($_POST['price']) && isset($_POST['includes']) && isset($_POST['pdfname'])){
$data = new MysqlClass();
$data->connetti();
$query = "INSERT INTO " . $section . " (
`id` ,
`title` ,
`offer` ,
`datestart` ,
`dateend` ,
`itinerary` ,
`price` ,
`includes` ,
`pdfname`)
VALUES (
NULL,
'".$title."',
'".$offer."',
'".$datestart."',
'".$dateend."',
'".$itinerary."',
'".$price."',
'".$includes."',
'".$pdfname."');";
$data->query($query);
echo "Viaggio inserito con successo.";
$data->disconnetti();
}
} else {
header("Location: index.html");
}
?>
EDIT: I'm using Wamp as a local server. I'm starting to think that's the problem, although it seems unlikely.
EDIT 2: I tried switching to EasyPHP, but I still have the same problem: Parse error: syntax error, unexpected '}' in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\input.php on line 50
error_reporting(E_ALL);ini_set("display_errors", "on");
– Asenar Nov 15 '13 at 16:43