I want an alert to pop up when I enter the else
. I have found two ways to do the alert.
echo "<script type=\"text/javascript\">alert(\"Error al crear sugerencia\");</script>";
either
echo '<script language="javascript">alert("Error al crear sugerencia");</script>';
But it doesn't alert me, it prints on the console
I leave you the PHP code
$asunto = str_replace("'", "''", $asunto);
$comunicacion = str_replace("'", "''", $comunicacion);
echo $insertNoticia="insert into ib_noticia_interna (ID_NOTICIA_INTERNA,ASUNTO_NOTICIA,CREADOR,CUERPO_NOTICIA,fecha_inicio_vis,fecha_fin_vis,imagen) values(ID_NOTICIA_INTERNA.nextval,'$asunto','$selectorDep','$comunicacion','$fechaIni','$fechaFin','$url')";
$parseNoticia = oci_parse($intranetconn, $insertNoticia);
$execNoticia = oci_execute($parseNoticia);
if ($execNoticia) {
createNotificacion($intranetconn,$asunto,$fechaIni,$fechaFin,$selectorDep,'comunicacion');
}else{
echo "<script type=\"text/javascript\">alert(\"Error al crear sugerencia\");</script>";
}
How can I make an ALERT in php? Why is it printed by console and it works for others?
I have found the bug and am reporting it in case someone has the same problem.
Turns out the PHP I was running was called via AJAX.
It turns out that when doing
console.log(data)
all theechos
andreturns
of the php they are shown by console.log.I have put
$('body').append(data);
and add the script that is returning the php.Correct code: