Codice PHP:
<?php
$host = 'localhost'; $username = 'root'; $password = ''; $name = 'prova';
try {
$db = new PDO('mysql:host=' .$host . ';dbname=' .$name, $username, $password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
echo '<h3>
Catch Connect Error--->>> ' . $e->getMessage() . '
</h3>'; return false; }
$query = 'SELECT * FROM pagine WHERE nome LIKE \'prova\' ';
$result = $db->query($query);
$result->fetch(PDO::FETCH_ASSOC)) {
echo '<form id="pagina_mod" action=\'\' method="post">
<textarea name="testo" id="testo" rows="10" cols="132" tabindex="1">'.$row['testo'] .'</textarea>
<input type="hidden" name="nome" value="'.$row['nome'].'" />
<span class="col2 testo_centro"><a href=\'gestione_page.php\' ><input type="submit" name="annulla" value="Annulla" /></a></span> <span class="col2 testo_centro">
<input type="submit" name="submit" value="Salva" /></span></form>'; }
if (isset($_POST['nome']))
{
$query = 'UPDATE pagine SET testo = \''.$_POST['testo'].'\' WHERE nome LIKE \''.$_POST['nome'].'\'';
try{
$db->beginTransaction();
$sql = $query; $stmt = $db->prepare($sql);
$stmt->bindParam(':testo', $_POST['testo']);
$stmt->execute(); $result = $db->commit(); }
catch (PDOException $e)
{ echo 'Si è verificata una PDO Exception.'; echo 'SQL Query: ', $sql; echo 'Errore: ' . $e->getMessage(); }
}$result->closeCursor();
$db = null;?>
Come dice all'inizio l'update non funziona se il testo ha tag img, hr, ul ecc. e il testo è lungo.
Mi da questo, errore:
codice:
Errore: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server