salve, sto provano ad fare l'inserimento e l'update delle mie etichette cloud tag(in inglese)..
ora l'inserimento e ok ecco il codice:
codice:
$lastId = $db->lastInsertId();
if(!empty($_POST['check_list'])) {
foreach($_POST['check_list'] as $check) {
$query = "INSERT INTO post_tags (id_tags,id_news,data_reg)VALUES(:id_tags,:id_news,:data_reg)";
$stmt = $db->prepare($query);
$stmt->bindParam(':id_tags', $check, PDO::PARAM_INT);
$stmt->bindParam(':id_news', $lastId, PDO::PARAM_INT);
$stmt->bindParam(':data_reg', $unisci_data, PDO::PARAM_STR);
$stmt->execute();
}
}
Da questa riga prendo l'ultimo inserimento che faccio per inserire le news:
$lastId = $db->lastInsertId();
e qui non ci sono problemi.
ora il form e composto cosi:
codice:
<tr>
<td>Tags</td>
<td><?php
$stmt = $db->prepare('SELECT * FROM tags');
$stmt->execute();
while(($row_tags = $stmt->fetch()) !== false)
{
?>
<input type="checkbox" name="check_list[]" value="<?php echo $row_tags["id"]; ?>"><?php echo $row_tags["name"]; ?>
<?php
}
?></td>
</tr>
e ok.
Ora la parte del modifica non mi riesce ansi lo fatto ma non capisco bene..
io vorrei fare il modo che quando uno modifica la notizia e modifica i tag i tag vengono cambiati.
ecco la parte del codice di update:
codice:
if(!empty($_POST['check_list'])) {
foreach($_POST['check_list'] as $check) {
$query_delete = "DELETE FROM post_tags WHERE id=:id";
$stmt = $db->prepare($query_delete);
$stmt->bindParam(':id', $lastId, PDO::PARAM_INT);
$stmt->execute();
$query = "UPDATE post_tags set id_tags=:id_tags,id_news=:id_news,data_reg=:data_reg WHERE id=:id";
$stmt = $db->prepare($query);
$stmt->bindParam(':id_tags', $check, PDO::PARAM_INT);
$stmt->bindParam(':id_news', $lastId, PDO::PARAM_INT);
$stmt->bindParam(':data_reg', $unisci_data, PDO::PARAM_STR);
$stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
$stmt->execute();
}
}
ma se provo non cancella e aggiorna..
come posso fare?
grazie mille e l'unica cosa che mi manca poi il sito che sto facendo a mia zia e finito.
grazie mille di nuovo.