Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(-1);
- ini_set('display_errors', 'On');
- ?>
- <?php
- $servername = "xxxx";
- $username = "xxxx";
- $password = "xxxxx";
- $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($user)) {
- $error[] = urlencode('Please enter a name.');
- }
- $cognome = isset($_POST['cognome']) ?
- trim($_POST['cognome']) : '';
- if (empty($user)) {
- $error[] = urlencode('Please select a lastname.');
- }
- $indirizzo = isset($_POST['indirizzo']) ?
- trim($_POST['indirizzo']) : '';
- if (empty($user)) {
- $error[] = urlencode('Please select a address.');
- }
- $civico = isset($_POST['civico']) ?
- trim($_POST['civico']) : '';
- if (empty($user)) {
- $error[] = urlencode('Please select a number.');
- }
- $citta = isset($_POST['citta']) ?
- trim($_POST['citta']) : '';
- if (empty($user)) {
- $error[] = urlencode('Please select a city.');
- }
- $prov = isset($_POST['prov']) ?
- trim($_POST['prov']) : '';
- if (empty($user)) {
- $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>
Advertisement
Add Comment
Please, Sign In to add comment