You can do an:
Code:
DELETE FROM sig WHERE user='$name'
Before saving your pic. It would work, but it's ugly.
Plus, sa you use a varchar field as key (I think), it's way from being an ideal case regarding the indexes.
You'd better use a numeric field as the primary key, which will link to another record holding the user name, username, and so on...
To be optimal, what you should do here, is re-create this table, with a primary key on the user field.
The primary key will prevent the database to allow more than 1 sig for a given user.
That way, no need to delete old records, they cannot exist.
Then, use a query like this:
Code:
INSERT INTO sig
(user, image)
VALUES
('$name','$img')
ON DUPLICATE KEY UPDATE image='$img'
Basically, you always try to insert data, but when the primary key will prevent the insertion (because a sig for this user already exists), it will automatically make an update of the existing record with your new image.
I dont know how portable this query can be !
I know it works for mysql5.0+, but I don't know if mysql4 can handle this syntax.
I don't know neither if the sql98 standard include this, so it may be proprietary for mysql.
I let you do the tests.
__________________
Listen to the ducky: "This is awesome!!!"
Last edited by tripy : 05-09-2007 at 12:18 PM.
|