Re: Save ability... Duplicate DB entries

From: Date: Sat, 10 Aug 2002 16:22:20 +0000
Subject: Re: Save ability... Duplicate DB entries
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-111953@lists.php.net to get a copy of this message
JJ, > i have this code snippet: > > if(isset($_POST['save'])){ > $query = 'INSERT INTO article_data VALUES (\'\', > '.$_SESSION['uid'].', > '.time().', \''.$_POST['title'].'\', > \''.$_POST['description'].'\', > '.$_POST['cat'].', \''.$_POST['text'].'\', > 0)'; > $result = mysql_query($query) or die("Query failed: $query<br>" . > mysql_error()); > echo 'you saved your work.'; > } elseif(isset($_POST['pub'])) { > $query = 'INSERT INTO article_data VALUES (\'\', > '.$_SESSION['uid'].', > '.time().', \''.$_POST['title'].'\', > \''.$_POST['description'].'\', > '.$_POST['cat'].', > \''.nl2br($_POST['text']).'\', 0)'; > echo 'you published your work.'; > } > > Which has a save or a publish option. I only want to keep one copy of each > article in the DB. This adds a new one each time. I know about updates in > SQL but the file may or may not already be in the db. Does anyone have a > good way to go about this? First perform a SELECT to establish previous existence (can lock row at this point, if using suitable RDBMS), then decide to INSERT or UPDATE, save or publish. Regards, =dn

« previous php.general (#111953) next »