First of all I want to say that I have already reviewed the possible answers to this in this and other forums. As indicated by the title, what I want to do is: if there is a record with the same number, launch an aletra with js and if not, register the new data. I'm using Dreamweaver, so the order and the name of some variables, apart I do not know if this can affect my code with respect to what I want to do.
$consulta = mysql_query("SELECT NUMERO_PLANILLA FROM huawei_rollout WHERE
NUMERO_PLANILLA = '$NUMERO_PLANILLA'", $conexion);
if(mysql_num_rows($consulta) > 0){
echo '<script>alert("El numero de Planilla ya existe");</script>';
}else{
if((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "frmGuardar")) {
$insertSQL = sprintf("INSERT INTO huawei_rollout (ID, FECHA, MES_EJECUCION,
MES_FACTURACION, CONTRATISTA) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['ID'], "int"),
GetSQLValueString($_POST['FECHA'], "date"),
GetSQLValueString($_POST['MES_EJECUCION'], "text"),
GetSQLValueString($_POST['MES_FACTURACION'], "text"));
mysql_select_db($database_conexion, $conexion);
$Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());
$insertGoTo = "ingre_plani_exi.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
}