Ver Mensaje Individual
  #4 (permalink)  
Antiguo 16/10/2012, 06:10
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Mensaje de alert para cuando el regisrtro existe en la base de datos

Estoy intentando hacer esto pero no me sale:


Boton en index.php

Código Javascript:
Ver original
  1. <a class="dock-item" onclick="javascript:TelefonoExiste()"><span>Validar</span><img src="imagenes_menu/untitled.png" alt="Validar" /></a>

valida.php


Código PHP:
Ver original
  1. <?php require_once('Connections/conexion.php'); ?>
  2. <?php
  3.  
  4.       $telefono = $_REQUEST['telefono'];
  5.  
  6.       $sql="SELECT telefono FROM usuarios WHERE telefono='$telefono'";
  7.  
  8.       $res=mysql_query($sql,Conectar::con());
  9.  
  10.        if(mysql_num_rows($res)>=1)
  11.  
  12.         echo "El nº de teléfono ya existe";
  13.  
  14.    ?>

y la funcion js

Código Javascript:
Ver original
  1. <script language=javascript>
  2. ///function valor existe//////
  3. function nuevoAjax() {
  4.  
  5.    var xmlhttp=false;
  6.  
  7.    try   {
  8.  
  9.       // Creacion del objeto AJAX para navegadores no IE
  10.  
  11.       xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  12.  
  13.    }
  14.  
  15.    catch(e)   {
  16.  
  17.      try  {
  18.  
  19.       // Creacion del objet AJAX para IE
  20.  
  21.       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  22.  
  23.      }
  24.  
  25.      catch(E) {
  26.  
  27.       if (!xmlhttp && typeof XMLHttpRequest!='undefined')
  28.  
  29.         xmlhttp=new XMLHttpRequest();
  30.  
  31.      }
  32.  
  33.    }
  34.  
  35.    return xmlhttp;
  36.  
  37.   }
  38.  
  39.  
  40.  
  41.   function TelefonoExiste(telefono) {
  42.  
  43.       var ajax=nuevoAjax();
  44.  
  45.       ajax.open("GET", "valida.php?telefono="+telefono, true);
  46.  
  47.       ajax.onreadystatechange=function() {
  48.  
  49.         if (ajax.readyState==4)
  50.  
  51.          TelefonoExiste=ajax.responseText;
  52.  
  53.       }
  54.  
  55.       ajax.send(null);
  56.  
  57.   }
  58. </script>

Gracias.