Error checking user in BBDD

0

I am developing a website that when entering the username I want to know if it exists or not. To do this, js picks up the input variable and sends it via POST to PHP

jQuery(function ($) {
$('#id_del_referido').blur(function(){

    $('#Info').html('<img src="/wp-content/uploads/2017/09/loader.gif" alt="" />').fadeOut(1000);

    var patrocinador = $('#id_del_referido').val();     
    var dataString =patrocinador;

    $.ajax({
        type: "POST",
        url: "/wp-content/themes/divi-hijo/comprobacion_patro.php",
        data: dataString,
        success: function(data) {
            $('#Info').fadeIn(1000).html(data);
            //alert(data);
        }
    });
});              
}); 

Once we have the value of the input he sent it by post to the php

I leave you the full php code

<?php
//variables y conexion mysql
$hostname="localhost";
$username="myinvestpa";
$password="jPd4qB06";
$dbname="investpainbbdd";
$patro=$_POST['patrocinador'];
$conn = mysqli_connect($hostname,$username,$password) or die ("<html><script     language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysqli_select_db($conn,$dbname);

//Realizamos la consulta sql

$query = "SELECT * FROM wp_users where user_nicename = '".$patro."'";
$results = mysqli_query($conn,$query) or die('ok');


  if(mysqli_num_rows(@$results) != 0){
    echo '<div id="Error">ID de patrocinador Correcto</div>';
  }
 if(mysqli_num_rows(@$results) == 0){
    echo '<div id="Succes">ID de patrocinador Incorrecto</div>';
 }
 ?>

The problem is that when I take the test it always gives me that the user is wrong. any idea or if the code is wrong?

    
asked by AitorUdabe 01.10.2017 в 15:52
source

2 answers

1

As you say you do not send the parameters well, since you are sending it without "tagging" said variable, it would be like this:

 var dataString = {"patrocinador" : patrocinador};
    
answered by 01.10.2017 / 20:26
source
1

Check if it's not the variable you send, try:

url: "/wp-content/themes/divi-hijo/comprobacion_patro.php?patro="+patrocinador,

and in the php $patro=$_GET['patrocinador'];

    
answered by 01.10.2017 в 21:09