123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
?>
<?php
$servername = "xxx";
$username = "xxx";
$password = "xxxx";
$dbname = "xxxx";
try {
$dbh = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$sth = $dbh->prepare("use accessibilita");
?>
<?php
switch ($_GET['action']) {
case 'add':
switch ($_GET['type']) {
case 'tages':
$error = array();
$nome = isset($_POST['nome']) ?
trim($_POST['nome']) : '';
if (empty($nome)) {
$error[] = urlencode('Please enter a name.');
}
$cognome = isset($_POST['cognome']) ?
trim($_POST['cognome']) : '';
if (empty($cognome)) {
$error[] = urlencode('Please select a lastname.');
}
$indirizzo = isset($_POST['indirizzo']) ?
trim($_POST['indirizzo']) : '';
if (empty($indirizzo)) {
$error[] = urlencode('Please select a address.');
}
$civico = isset($_POST['civico']) ?
trim($_POST['civico']) : '';
if (empty($civico)) {
$error[] = urlencode('Please select a number.');
}
$citta = isset($_POST['citta']) ?
trim($_POST['citta']) : '';
if (empty($citta)) {
$error[] = urlencode('Please select a city.');
}
$prov = isset($_POST['prov']) ?
trim($_POST['prov']) : '';
if (empty($prov)) {
$error[] = urlencode('Please select a county.');
}
if (empty($error)) {
$stmt = $dbh->prepare("INSERT INTO tagesroma(nome, cognome, indirizzo, civico, citta, prov)
VALUES (:nome, :cognome, :indirizzo, :civico, :citta, :prov)");
$stmt->bindParam(':nome', $nome);
$stmt->bindParam(':cognome', $cognome);
$stmt->bindParam(':indirizzo', $indirizzo);
$stmt->bindParam(':civico', $civico);
$stmt->bindParam(':citta', $citta);
$stmt->bindParam(':prov', $prov);
$stmt -> execute();
} else {
header('Location:tages.php?action=add' .
'&error=' . join($error, urlencode('<br/>')));
}
break;
}
break;
case 'edit':
switch ($_GET['type']) {
case 'tages':
$error = array();
$nome = isset($_POST['nome']) ?
trim($_POST['nome']) : '';
if (empty($nome)) {
$error[] = urlencode('Please enter a name.');
}
$cognome = isset($_POST['cognome']) ?
trim($_POST['cognome']) : '';
if (empty($cognome)) {
$error[] = urlencode('Please select a lastname.');
}
$indirizzo = isset($_POST['indirizzo']) ?
trim($_POST['indirizzo']) : '';
if (empty($indirizzo)) {
$error[] = urlencode('Please select a address.');
}
$civico = isset($_POST['civico']) ?
trim($_POST['civico']) : '';
if (empty($civico)) {
$error[] = urlencode('Please select a number.');
}
$citta = isset($_POST['citta']) ?
trim($_POST['citta']) : '';
if (empty($citta)) {
$error[] = urlencode('Please select a city.');
}
$prov = isset($_POST['prov']) ?
trim($_POST['prov']) : '';
if (empty($prov)) {
$error[] = urlencode('Please select a county.');
}
if (empty($error)) {
$stmt = $dbh->prepare("UPDATE tagesroma SET nome=?, cognome=?, indirizzo=?, civico=?, citta=?, prov=? WHERE id=?"); // changed to WHERE id=?
$stmt->execute(array($nome, $cognome, $indirizzo, $civico, $citta, $prov,$_GET["id"])); // added $_GET["id"] to the end
} else {
header('Location:tages.php?action=edit&id=' . $_GET['id'] .
'&error=' . join($error, urlencode('<br/>')));
}
break;
}
break;
}
?>
<html>
<head>
<title>Commit</title>
<meta charset="UTF-8">
</head>
<body>
<p>Done!</p>
<a title="Torna Indietro" href="admin.php">Torna Indietro</a>
</body>
</html>