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.

 

 

 

Link to comment
Share on other sites

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);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.