It seems when I submit this update script that it does not display the updated value in the form (it does, however, update properly in the database). It displays the previous date, like it doesn't update the date field. It updates the rest and displays the change, just not the date change.
I hope that makes sort of sense? Basically it does what it's supposed to, works fine, but doesn't display the changed date in the form after you hit Save Article (every other field is fine). Fairly sure there's something up with the logic, but I can't see it (new to PHP really).
Here's my code:
<?php
$query = "SELECT id, title, FROM_UNIXTIME(release_date, '%d/%m/%Y') as release_date, picture, tracks, format, link FROM releases WHERE id = '{$_GET['id']}'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$title = $row['title'];
$dttm = $row['release_date'];
$picture = $row['picture'];
$tracks = $row['tracks'];
$format = $row['format'];
$link = $row['link'];
}
if(isset($_POST['save']))
{
$title = $_POST['title'];
list($day, $month, $year) = split('/', $_POST['release_date']); //split the date up
$release_date = mktime(0, 0, 0, $month, $day, $year); //put it in a unix timestamp
$format = $_POST['format'];
$link = $_POST['link'];
if (isset($_POST['tracks'])) {
$tracks = addslashes($_POST['tracks']);
}
// update the release in the database
$query = "UPDATE releases ".
"SET title = '$title', release_date = '$release_date', format = '$format', link = '$link', tracks = '$tracks' WHERE id = '{$_GET['id']}'";
mysql_query($query) or die('Error : ' . mysql_error());
echo "'$title' updated";
}
?>
Any help is appreciated 🙂