Show alert or error message on mobile

0

I have a site, and it has the registration and when the registration already exists it shows an alert saying this (this alert I did in js, but it was inside the php), but when I put the page to be mobile, the alert does not appear, how do I post or show an error message? (all this by php)

The user will put the cpf and email to do the registration, if you already have in the bd, he will inform. Here's how:

PAGE: processa.php

if (mysqli_num_rows($querySelect) > 0) {
    echo"<script type='text/javascript'>alert('Alguém com esses dados já se cadastrou. Tente novamente.');window.location.href='cadastro.php';</script>";
}

But I wanted the alert to show the mobile too, but it does not show.

This is the registration page (I will only put the button):

Page: cadastro.php

<button type="submit" class="btn btn-primary btn-lg btn-block" id="cadastrar" name="cadastrar" disbled/ >
<span class="glyphicon glyphicon-ok"></span>
<span id="cpf"></span>Cadastrar</button>
    
asked by anonymous 07.12.2017 / 13:36

2 answers

0

In your HTML:

<p id="erromsg" style="display:none"></p>

In PHP

if (mysqli_num_rows($querySelect) > 0) {
$msg = "Alguém com esses dados já se cadastrou. Tente novamente";
$out="<script type='text/javascript'>$('#erromsg').text( $msg ).show(); window.location.href='cadastro.php';</script>";
echo $out;
}
    
07.12.2017 / 16:00
0

I suggest using a small modal, as shown in the figure below:

Code:

if(mysqli_num_rows($querySelect)>0){$msg_alerta='<spanid="alertabox" style="display:block;position:fixed;width:200px;padding:5px 20px 20px;background:#ddd;border:1px solid #999;text-align:center;transform:translate(-50%,-50%);top:50%;left:50%;z-index:99999;">
   <h1>Aviso</h1>
   <p>Alguém com esses dados já se cadastrou. Tente novamente.</p>
   <input style="padding:5px 10px;" type="button" value="OK" onclick="$(\'#alertabox\').remove();window.location.href=\'cadastro.php\';" />
   </span>';
   echo $msg_alerta;
}

Alternative (no redirection)

Enter the span shortly after the Add button:

<?php
<span style="display:none;" id="msg_alerta">Alguém com esses dados já se cadastrou. Tente novamente.</span>
?>

And use the code below in PHP:

if (mysqli_num_rows($querySelect) > 0) {
    $erro_cadastro = 
   echo '<script>window.onload=function(){document.getElementById("msg_alerta").style.display="block";}</script>';
}

Alternative 2 (no redirection)

Enter the code below after the Register button:

<?php
if($erro_cadastro){
    echo '<span style="display:block;" id="msg_alerta">Alguém com esses dados já se cadastrou. Tente novamente.</span>';
}
?>

And in PHP:

<?php
$erro_cadastro = false;
if (mysqli_num_rows($querySelect) > 0) {
   $erro_cadastro = true;
}
?>
    
07.12.2017 / 16:45