It is almost safe, but not entirely, since another user could slip in a row
with your number in the split second between your Select ... and your
Insert. That is the case for blocking the Select ... Insert sequence as one
logical unit of work so the target table is locked from Select through
Insert.

PB

-----
  ----- Original Message -----
  From: John Griffin
  To: Steve Marquez ; MySQL List
  Cc: PHP eMail List
  Sent: Friday, June 06, 2003 2:51 PM
  Subject: RE: Duplicate records


  Hello Steve,

  Do a select on the record before you insert it. If the record does not
exist in the database (i.e. mysql_num_rows () == 0) than it is safe to do
the insert.

  John

  -----Original Message-----
  From: Steve Marquez [mailto:[EMAIL PROTECTED]
  Sent: Friday, June 06, 2003 3:41 PM
  To: MySQL List
  Cc: PHP eMail List
  Subject: Duplicate records


  Hello.

  I am adding a record to a MySQL Database using PHP. I have the records
  listed by the field: $id_num.

  I want the DB to be updated only with new id numbers, and return an error
if
  there is a duplicate number already in the DB.

  Here is the code I am using:

  <?php

  $insert_data = "INSERT into articles

  Values ( '<a href=\"upload_form.php?id_num=$id_num\">edit</a>', '<a
  href=\"delete.php?id_num=$id_num\">delete</a>', '$id_num', '$title',
  '$author', '$article_contents', '$start_date', '' );";

  $response = mysql_query( $insert_data, $dbh );


  $get_table_data = "SELECT * FROM ccfs";
  $response = mysql_query( $get_table_data, $dbh );

  ?>

  Can anyone help me? Hope this makes sense.

  Thanks!

  Steve Marquez
  Marquez Design
  [EMAIL PROTECTED]

  www.marquez-design.com


  --
  MySQL General Mailing List
  For list archives: http://lists.mysql.com/mysql
  To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]



  --
  MySQL General Mailing List
  For list archives: http://lists.mysql.com/mysql
  To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to