Código PHP :
<?php $cnb = mysql_connect("localhost","root",""); $dbselectb = mysql_select_db('migra1',$cnb); $sql3 = "select * from tabla "; $rs3 = mysql_query($sql3,$cnb); $val3 = mysql_fetch_array($rs3); $codigo = $val3['codigo']; $marca = $val3['MARCA']; $cn = mysql_connect("localhost","root",""); $dbselect = mysql_select_db('migra2',$cn); $sql = "select * from tabla "; $rs = mysql_query($sql3,$cn); $val = mysql_fetch_array($rs); $codigo2 = $val['codigo']; if($codigo==$codigo2){ $cns=mysql_connect("localhost","root",""); $dbselectb = mysql_select_db('migra2',$cns); $sql = "REPLACE INTO tabla( MARCA) VALUES ( '$marca') "; $sql."<br>"; }else{ $con= mysql_connect("localhost","root",""); $db = mysql_select_db('migra2',$con); $sql ="INSERT INTO tabla ( CODIGO,MARCA) VALUES ( '$codigo', '$marca')"; $sql29."<br>"; } $i++; $result = mysql_query($sql); mysql_close(); ?>