Show Alert or mobile error message

Asked

Viewed 238 times

0

I have a website, 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 within php), but when I put the page to be mobile, the Alert does not appear, as I put to appear or show an error message? (all this by php)

The user will put Cpf and email to register, if you already have in the bd, he will inform. Ta thus:

PAGE: processes.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 Alert to show the mobile too, only it doesn’t show.

This is the registration page (I’ll just put the boot):

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>
  • Show me what you got.

  • @Thiago Pronto.

  • I would use http://api.jquery.com/jquery.ajax/ to request the page processa.php and she would simply have as a body the result of the condition of mysqli_num_rows($querySelect) > 0 that would be true or false and then you would show an Alert if the result of the request was true. This would work perfectly on desktop and mobile and would be pleasant to the user since there would be no kind of redirection.

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;
}
  • this part: #erromsg"). text( $msg ).show(); window.location.href='cadastro.php';</script>"; was the comment, not?

  • There was an error in the Apas, now I corrected check there

  • The php page that I put this is all blank

0

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

inserir a descrição da imagem aqui

Code:

if (mysqli_num_rows($querySelect) > 0) {
   $msg_alerta = '<span id="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 (without redirection)

Insert the span right after the button Register:

<?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 button Register:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.