The idea in this code is to print the amount of followers that an user has...
This is the code I've created
AJAX
$(document).ready(function() {
var usuario = $(".left h4").attr("data-id");
var seguidor = $("#user_account_info .profile_ball").attr("data-id");
$.ajax({
type: "POST",
url: "./include/php/followers.php",
data: { user: usuario, follower: seguidor },
success: function(data) { $(".right h4 i").html(data); }
});
return false;
});
PHP
<?php
$dsn = "mysql:host=localhost;dbname=tapehd;charset=utf8";
$usuario = "root";
$contraseña = "";
$conexion = new PDO($dsn, $usuario, $contraseña);
$resultado = null;
$user = $_POST["user"];
$seguidor = $_POST["follower"];
$sql = "SELECT count(*) as seguidores FROM seguidores WHERE id_canal = '$user'";
if(isset($resultado)){ $datos = $resultado->fetch(); }
$seguidores = $datos["seguidores"];
return $seguidores;
?>
I'm returning the result in the php file and taking back the data in the php one. I print in the div I want to display, but it shows me only an error:
Notice: Undefined variable: datos in C:\wamp\www\tapeHD\include\php\followers.php on line 16