if ($email != $CURUSER["email"]) {
if (!validemail($email))
bark( _("Klaida! Panašu, kad klaidingai įvedei email adresą!") );
$r = do_mysql_query("SELECT id FROM users WHERE email=" . sqlesc($email)) or sqlerr();
if (mysql_num_rows($r) > 0)
bark( sprintf( _("Toks emailas adresas %s jau naudojamas!"), $email) );
####
$date = date("Y-m-d");
$modcomment_email = "{$date} - E-mail pakeistas, pakeitė: {$CURUSER['username']}";
$modcomment_email = mysql_real_escape_string($modcomment_email);
do_mysql_query("UPDATE users SET modcomment = '$modcomment_email' where id = ".$CURUSER['id']) or sqlerr(__FILE__, __LINE__);
#####
$changedemail = 1;
}
After this script executed row updated, but old data deleted. How update row, but keep old data ?
You're using an UPDATE
command. This does, as you've observed, modify the row(s) that match your WHERE
clause.
If you'd like to keep the list of previous $modcomment_emails
then you'll need to use an INSERT
into some table and then make sure you're selecting the most recent record out when you do your SELECT
to output the data. You could add a column to keep the date of the insert as something to ORDER BY
.
If you need to keep the old data, you would have to move a copy into an archive table, by issuing the "update" command it overwrites anything that was there. Example
if I have a table where username is "Bugfinder" and now, I change the username to "Bug" there will be no reference to Bugfinder because it was overwritten. If I wanted to keep that, I would need to have copied the line into an archive table maybe a long with the date/time of change, so I could look back historically for changes.
Yes - if you want to insert new row use INSERT
if want to update use UPDATE
. Also solution is to create history table when you would drop needed old date with the time when change happend