[PHP] Save ability... Duplicate DB entries

2002-08-10 Thread JJ Harrison

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: $querybr .
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?




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Save ability... Duplicate DB entries

2002-08-10 Thread DL Neil

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: $querybr .
 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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Save ability... Duplicate DB entries

2002-08-10 Thread Mark Charette

Or, of course, a selection of fields as a unique key. The insert will fail
if there is an exisiting record with that key; you can interrogate the error
and report on the exisitence of a duplicate record.

The select/lock method is used for update purposes ('select for update' et
al.), not to keep duplicate records out of the DB.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Save ability... Duplicate DB entries

2002-08-10 Thread Analysis Solutions

Hi JJ:

On Sun, Aug 11, 2002 at 01:44:53AM +1000, JJ Harrison wrote:
 
 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?

Here's a quick outline of what I do.  I have a form for entering in
articles.  If the form is opened without an ArticleID, the ArticleID (a
hidden form field) becomes 0.  But, if the form is opened with an
ArticleID, the given ArticleID is put in the hidden field.

Now, when I make my changes and hit the Save (submit) button, the script 
checks the ArticleID.  If it's 0, do an insert.  If it's non-zero, do an 
update.

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Save ability... Duplicate DB entries

2002-08-10 Thread JJ Harrison

I'll do that. When I load an article I supply the article's id.


--
JJ Harrison
[EMAIL PROTECTED]
www.tececo.com

--
Please reply on the list/newsgroup unless the reply it OT.

Analysis  Solutions [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hi JJ:

 On Sun, Aug 11, 2002 at 01:44:53AM +1000, JJ Harrison wrote:
 
  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?

 Here's a quick outline of what I do.  I have a form for entering in
 articles.  If the form is opened without an ArticleID, the ArticleID (a
 hidden form field) becomes 0.  But, if the form is opened with an
 ArticleID, the given ArticleID is put in the hidden field.

 Now, when I make my changes and hit the Save (submit) button, the script
 checks the ArticleID.  If it's 0, do an insert.  If it's non-zero, do an
 update.

 --Dan

 --
PHP classes that make web design easier
 SQL Solution  |   Layout Solution   |  Form Solution
 sqlsolution.info  | layoutsolution.info |  formsolution.info
  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
  4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php