Jump to content

Ho to check record existence and write if not exist?


coder9

Recommended Posts

ok

 

i have this table name: jtable

with two columns: id and box_no

 

now what i want is to check first if $link has the same value already in box_no column.

 

I want the search to search all the records in the table if $link has duplicate already under box_no column

 

if duplicate found, then don't write $link value  into box_no column.

 

if it doesn't have duplicate, then write the value of $link into box_no column.

 

now my humble request is this could you show me how is this done using PHP & MySQL?

 

Thank you very much in advance.

 

 

 

sudo code...

$strQuery1 = "select count(*) as cnt from jtable where box_no='".$link."'";
$res = mysql_query($strQuery1);
$row = mysql_fetch_array($res);
$intCount = $row['cnt'];

if($intCount == 0) {
  $strQuery2 = "insert into jtable (box_no) values ('".$link."')";//assumption id is auto-incremented.
  $res2 = mysql_query($strQuery2);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.